createContract
createContract<
TName
,TAbi
,TAddress
,TBytecode
,TDeployedBytecode
,TCode
,THumanReadableAbi
>(__namedParameters
):Contract
<TName
,THumanReadableAbi
,TAddress
,TBytecode
,TDeployedBytecode
,TCode
>
Creates a Tevm Contract instance from a human-readable ABI or JSON ABI. This function is the core of Tevm’s contract interaction capabilities, allowing for type-safe and easy-to-use contract interfaces.
Type Parameters
• TName extends string
• TAbi extends Abi
| readonly string
[]
• TAddress extends undefined
| `0x${string}` = undefined
• TBytecode extends undefined
| `0x${string}` = undefined
• TDeployedBytecode extends undefined
| `0x${string}` = undefined
• TCode extends undefined
| `0x${string}` = undefined
• THumanReadableAbi extends readonly string
[] = TAbi
extends readonly string
[] ? TAbi
<TAbi
> : TAbi
extends Abi
? FormatAbi
<TAbi
<TAbi
>> : never
Parameters
• __namedParameters: CreateContractParams
<TName
, TAbi
, TAddress
, TBytecode
, TDeployedBytecode
, TCode
>
Returns
Contract
<TName
, THumanReadableAbi
, TAddress
, TBytecode
, TDeployedBytecode
, TCode
>
Throws
If neither humanReadableAbi nor abi is provided.
Examples
Using a human-readable ABI:
Using a JSON ABI:
See
- Contract for the full API of the returned Contract instance.
- https://tevm.sh/learn/contracts/ for more information on working with contracts in Tevm.
- https://tevm.sh/reference/tevm/contract/types/Contract/ for detailed Contract type documentation.