Script
Script<
TName
,THumanReadableAbi
>:object
An action creator for Tevm.script
, Tevm.contract
and more
representing a solidity contract bytecode and ABI.
Scripts are akin to Foundry scripts you can run in the Tevm vm.
Script is also is the type solidity contract imports are turned into.
Scripts and contracts generate actions that can be dispatched to tevm methods
such as contract
and script
Examples
A script can be made via the createScript
function
These scripts 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
Scripts can also be used with other libraries such as Viem and ethers.
bytecode
bytecode:
Hex
The contract bytecode. This can be used for deploying the contract bytecode is different from deployedBytecode in that the bytecode includes the code to deploy the contract whereas the deployed bytecode is the code that is deployed
deployedBytecode
deployedBytecode:
Hex
The deployed contract bytecode. TThis can be used with the script
tevm method
to execute arbitrary solidity code that isn’t necessarily deployed to the chain
deployedBytecode is different from bytecode in that the bytecode includes the code
to deploy the contract whereas the deployed bytecode is the code that is deployed
events
events:
EventActionCreator
<THumanReadableAbi
,Hex
,Hex
,undefined
>
Action creators for events. Can be used to create event filters in a typesafe way
Example
name
name:
TName
The name of the contract. If imported this will match the name of the contract import
read
read:
ReadActionCreator
<THumanReadableAbi
,Hex
,Hex
,undefined
>
Action creators for contract view and pure functions
Example
withAddress()
withAddress: <
TAddress
>(address
) =>Omit
<Script
<TName
,THumanReadableAbi
>,"events"
|"read"
|"write"
|"address"
> &object
Adds an address to the contract. All action creators will return the address property if added.
Example
Note this is not necessary with tevm.script
method that doesn’t require
a contract address to execute
Type parameters
• TAddress extends Address
Parameters
• address: TAddress
Returns
Omit
<Script
<TName
, THumanReadableAbi
>, "events"
| "read"
| "write"
| "address"
> & object
write
write:
WriteActionCreator
<THumanReadableAbi
,Hex
,Hex
,undefined
>
Action creators for contract payable and nonpayable functions
Example
Source
Script.ts:64