Contract
Contract<
TName
,THumanReadableAbi
,TAddress
,TBytecode
,TDeployedBytecode
,TCode
>:object
Represents a specific contract abi and optional bytecode.
Examples
Contracts have actions creators for read methods, write methods, deploying, and events
These contracts can be automatically generated by using @tevm/bundler and then importing it. The Tevm bundler will automatically resolve your solidity imports into tevm contract instances
Address can be added to a contract using the withAddress
method
Contracts can also be used with other libraries such as Viem and ethers.
address
address:
TAddress
Configured address of the contract. If not set it will be undefined
To set use the withAddress
method
bytecode
bytecode:
TBytecode
The contract bytecode is not defined on Contract objects are expected
to be deployed to the chain. See Script
type which is a contract with bytecode
It’s provided here to allow easier access of the property when using a
Contract | Script
union type
code
code:
TCode
Code i
deploy()
deploy: (…
args
) =>EncodeDeployDataParameters
<ParseAbi
<THumanReadableAbi
>>
Action creator for deploying the contract
Parameters
• …args: EncodeDeployDataParameters
<ParseAbi
<THumanReadableAbi
>> extends object
? TArgs
extends ReadonlyArray
<any
> ? TArgs
: [] : []
Returns
EncodeDeployDataParameters
<ParseAbi
<THumanReadableAbi
>>
deployedBytecode
deployedBytecode:
TDeployedBytecode
The contract deployedBytecode is not defined on Contract objects are expected
to be deployed to the chain. See Script
type which is a contract with deployedBytecode
It’s provided here to allow easier access of the property when using a
Contract | Script
union type
events
events:
EventActionCreator
<THumanReadableAbi
,TAddress
,TBytecode
,TDeployedBytecode
>
Action creators for events. Can be used to create event filters in a typesafe way
Example
name?
optional
name:TName
The name of the contract. If imported this will match the name of the contract import
read
read:
ReadActionCreator
<THumanReadableAbi
,TAddress
,TCode
>
Action creators for contract view and pure functions
Example
script
script:
CreateScript
<TName
,THumanReadableAbi
,TAddress
,TBytecode
>
Creates a deployless instance of the contract that can be used with tevm and viem as deployless contracts
withAddress()
withAddress: <
TAddress
>(address
) =>Contract
<TName
,THumanReadableAbi
,TAddress
,TBytecode
,TDeployedBytecode
,TCode
>
Adds an address to the contract. All action creators will return the address property if added. THis method returns a new contract it does not modify the existing contract.
Example
Type Parameters
• TAddress extends Address
Parameters
• address: TAddress
Returns
Contract
<TName
, THumanReadableAbi
, TAddress
, TBytecode
, TDeployedBytecode
, TCode
>
write
write:
WriteActionCreator
<THumanReadableAbi
,TAddress
,TCode
>
Action creators for contract payable and nonpayable functions