EVM Integration
Tomo Extension Wallet injects tomo_evm
into the window object in your browser. dApp can easily interact with the wallet via window.tomo_evm
. The following demo code shows how it works:
const example = async () => {
// connect to tomo wallet and get accounts
const accounts = await window.tomo_evm.request({ method: 'eth_requestAccounts' })
// the first account is the selected account
const account = accounts[0]
// get chain id
const chainId = await window.tomo_evm.request({ method: 'eth_chainId' });
const txParams = {
nonce: '0x0',
gasPrice: '0x3e95ba80', // set by user from dApp
gas: '0x2710', // set by user from dApp
to: '0x0000000000000000000000000000000000000000',
from: account,
value: '0x2386f26fc10000',
chainId: chainId,
};
const txHash = await window.tomo_evm.request({
method: 'eth_sendTransaction',
params: [txParams],
});
}
const handleAccountsChanged = async (accounts) => {
// do something when account changed
}
window.tomo_evm.on('accountsChanged', handleAccountsChanged);
const handleChainChanged = async (chainId) => {
// do something when chain changed
}
window.tomo_evm.on('chainChanged', handleChainChanged)
Tomo extension wallet support the following standard JSON-RPC API:
eth_requestAccounts
eth_accounts
wallet_addEthereumChain
wallet_switchEthereumChain
wallet_watchAsset
eth_sign
personal_sign
eth_signTypedData_v4
eth_chainId
eth_gasPrice
eth_getBalance
eth_call
eth_sendTransaction
...
Last updated