EVM
Quick start
git checkout devgit pull # make sure you have the latest changesgit checkout -b my-custom-world # create a new branch for your customized worldnpx hypkg apply drama-haus/evmnpm install # install the EVM dependencies (wagmi and viem)Environment Configuration
The EVM integration requires the following environment variables to be added to your .env file:
# Required for all modesPUBLIC_EVM=mainnet # EVM chain to use (defaults to 'mainnet')
# For server wallet operationsEVM_SEED_PHRASE= # Required for server wallet operationsUsing in scripts
The integration exposes player.evm and world.evm to scripts:
player.evmcontains the connected wallet address of that playerworld.evmprovides access to EVM functionality and utilities
Player Properties
// Get the current player's wallet addressconst player = world.getPlayer()console.log(player.evm) // Returns the player's wallet addressWorld Properties
The world.evm object provides the following structure:
world.evm = { actions: {}, // wagmi actions utils: {}, // viem utilities abis: { erc20: erc20Abi, erc721: null }}Client-Side Actions
On the client side, all wagmi actions are automatically bound to the world object and available through world.evm.actions. These actions are pre-configured with the current wagmi config and can be used directly:
// Example of using client-side actionsconst result = await world.evm.actions.readContract({ address: '0x...', abi: world.evm.abis.erc20, functionName: 'balanceOf', args: [player.evm]})
// Write operations are also availableconst tx = await world.evm.actions.writeContract({ address: '0x...', abi: world.evm.abis.erc20, functionName: 'transfer', args: [recipientAddress, amount]})Contract Interactions
The EVM integration provides access to contract interactions through world.evm.actions and world.evm.getContract().
Basic Usage
// Access a contract by its addressconst contract = world.evm.getContract({ address: '0x...', abi: world.evm.abis.erc20})
// Read from a contractconst balance = await world.evm.actions.readContract({ address: '0x...', abi: world.evm.abis.erc20, functionName: 'balanceOf', args: [player.evm]})Common Contract Methods
These methods are available in both server and client contexts:
// Get a wallet's token balanceconst balance = await world.evm.actions.readContract({ address: tokenAddress, abi: world.evm.abis.erc20, functionName: 'balanceOf', args: [walletAddress]})
// Transfer tokensconst transferResult = await world.evm.actions.writeContract({ address: tokenAddress, abi: world.evm.abis.erc20, functionName: 'transfer', args: [recipientAddress, amount]})Example
app.on('update', () => { const player = world.getPlayer() if (player.evm) { // Player has a connected wallet const contract = world.evm.getContract({ address: '0x...', abi: world.evm.abis.erc20 })
// Use wagmi actions const balance = await world.evm.actions.readContract({ address: '0x...', abi: world.evm.abis.erc20, functionName: 'balanceOf', args: [player.evm] })
if (balance > 0) { app.send('client:balance', [balance, player.evm]) } }})