Interactions Overview
Overview
Smart contracts on OP_NET are accessed through the Contract class and the getContract() factory function. Contract interactions follow a two-phase pattern consisting of simulation and execution.
Simulation vs Execution
OP_NET separates contract calls into two distinct phases, each serving a specific purpose in the contract interaction workflow:
- Simulation (Read Operations): Executes contract code without creating a transaction. Use simulations for reading contract state, checking balances, verifying transactions before sending, and querying metadata.
- Execution (Write Operations): Creates a Bitcoin transaction that triggers contract execution. Use execution for transferring tokens, modifying contract state, deploying contracts, and any state-changing operation.
ABI System
To facilitate type-safe interactions, the library relies on ABIs (Application Binary Interface) that define the contract interface. ABIs specify function signatures, parameter types, return types, and event definitions, enabling compile-time validation and IntelliSense support.
CallResult
Every contract call returns a CallResult object. This object encapsulates the call outcome, including decoded return values, revert information, gas estimates, emitted events, and the access list for optimization purposes.
Contract Interaction Flow
Contract interactions follow a consistent pattern where the application calls a method on the contract instance, which encodes the calldata and sends it to the provider. The provider forwards the request to an OP_NET node, which executes the contract in the VM and returns the result. The response is then decoded and returned to the application as a typed CallResult object.