VM API By Example
Given this contract:
What happens when the Ethscriptions VM receives an ethscription with this data uri?
Step 1: Ethscription Validation
The Ethscriptions VM first validates the incoming Ethscription transaction.
It extracts the
content_uri
and decodes it to obtain the JSON payload containingcontractId
,functionName
, andargs
.
Step 2: Contract Lookup
The VM queries the
contracts
table to find the corresponding contract using thecontractId
provided (0xdb6c87fd9b5e1aafdbc9cf4550856abde133e08e04910fe5fc319b63f5c08b3f
in this case).If the contract exists the VM proceeds to the next step.
Step 3: Pre-Execution State
The VM fetches the latest state of the contract from the
contract_states
table based on thecontract_id
.The VM uses this state to set the initial values of state variables such as
maxSupply
,perMintLimit
, andtotalSupply
.
Step 4: Function Parameters Validation
The VM determines that the mint function exists on the contract.
The VM then validates the parameters passed to the
mint
function, in this case,amount: 5
. This includes type validations.Checks are made according to the conditions in the smart contract:
amount
must be positiveamount
must be less than or equal toperMintLimit
totalSupply
+amount
must be less than or equal tomaxSupply
Step 5: Execute Mint Function
If the validation checks pass, the VM calls the
mint
function._mint
is internally invoked, which increases thetotalSupply
and updates the balance ofmsg.sender
.
Step 6: Post-Execution State
A new entry is added to the
contract_states
table to reflect the state change post-minting.This includes the updated
totalSupply
, and the updated balance formsg.sender
.
Step 7: Log Receipt
A new row is inserted into the
contract_call_receipts
table, containing details of the function call, including:contract_id
ethscription_id
caller
status
(indicating success or failure)function_name
(in this case, "mint")function_args
(in this case,{"amount": 5}
)logs
(any events emitted or other logs)timestamp
Step 8: API Availability
After the execution and logging, all this newly created data becomes available via API endpoints for querying or analysis.
Through these steps, the Ethscriptions VM efficiently executes the contract method, updates the state, and logs all necessary information for further interactions or audits.
Last updated