Interacting with EVM Contracts
Contract Interface Definition
Define EVM contract interfaces using decorators:
@gl.evm.contract_interface
class TokenContract:
class View:
def balance_of(self, owner: Address) -> u256: ...
def total_supply(self) -> u256: ...
class Write:
def transfer(self, to: Address, amount: u256) -> bool: ...
def approve(self, spender: Address, amount: u256) -> bool: ...Calling EVM Contracts
Interact with EVM contracts through defined interfaces:
token_address: Address = ...
# Read from EVM contract
token = TokenContract(token_address)
supply = token.view().total_supply()
# Write to EVM contract
token.emit().transfer(receiver_address, u256(100))Balance Access
Access EVM contract balances directly:
evm_contract = TokenContract(address)
balance = evm_contract.balance # Get contract's ETH balanceMessage Emission
Send messages to EVM contracts:
TokenContract(token_address).emit().approve(spender, amount)Messages to EVM contract can be emitted only on finality