EVM Provider

The Tomo Telegram SDK implements the Ethereum Provider, allowing seamless integration with existing Ethereum-compatible DApps. Below are methods that developers can use with our EVM provider.

isConnected

The isConnected method returns a boolean value indicating whether the wallet is connected or not.

  ethereum.isConnected(): boolean

Request Method

The request method is used to make an RPC request to the connected wallet.

interface RequestArguments {
  id?: number | string;
  method: string;
  params?: Array<unknown> ;
}

ethereum.request = (payload: RequestArguments): Promise<any> 

For detailed information on JSON-RPC methods, refer to:

We provide some frequently use methods as below:

eth_requestAccounts

Connects to the wallet and returns the address of the connected wallet.

const accounts = await ethereum.request({ method: 'eth_requestAccounts' });

eth_accounts

Returns the address of the connected wallet.

const accounts = await ethereum.request({ method: 'eth_accounts' });

eth_chainId

Returns the chain ID of the connected wallet.

const chainId = await ethereum.request({ method: 'eth_chainId' });

wallet_switchEthereumChain

Switches the connected wallet to the specified chain ID.

try {
  await ethereum.request({
    method: 'wallet_switchEthereumChain',
    params: [{ chainId: '0xf00' }],
  });
} catch (switchError) {
  // error handle
}

eth_sendTransaction

Sends a transaction to the connected wallet.

For detailed usage, refer to:


const accounts = await ethereum.request({ method: 'eth_accounts' });
const transactionParameters = {
  nonce: '0x00',
  gasPrice: '0x09184e72a000',
  gas: '0x2710',
  to: '0x0000000000000000000000000000000000000000',
  from: accounts[0],
  value: '0x00',
  data: '0x7f7465737432000000000000000000000000000000000000000000000000000000600057',
  chainId: '0x3',
};

const txHash = await ethereum.request({
  method: 'eth_sendTransaction',
  params: [transactionParameters]
});

Signing Methods

The Tomo Telegram SDK supports various signing methods under Metamask standard:

  • personal_sign

  • eth_signTypedData

  • eth_signTypedData_v3

  • eth_signTypedData_v4

For detailed usage, refer to:

Example of personal_sign:

const accounts = await ethereum.request({ method: 'eth_accounts' });
const chainId =  await ethereum.request({ method: 'eth_chainId' });

const signature = await ethereum.request({
  method: 'personal_sign',
  params: ['Hello, Tomo!', accounts[0]]
});

Example of eth_signTypedData_v4:


const  accounts = await ethereum.request({ method: 'eth_accounts' });
const  chainId  =  await ethereum.request({ method: 'eth_chainId' });

const  msgParams = {
    "domain": {
        "chainId": chainId,
        "name": "Ether Mail",
        "verifyingContract": "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC",
        "version": "1"
    },
    "message": {
        "contents": "Hello, Bob!",
        "from": {
            "name": "Cow",
            "wallets": [
                "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826",
                "0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF"
            ]
        },
        "to": [
            {
                "name": "Bob",
                "wallets": [
                    "0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB",
                    "0xB0BdaBea57B0BDABeA57b0bdABEA57b0BDabEa57",
                    "0xB0B0b0b0b0b0B000000000000000000000000000"
                ]
            }
        ],
        "attachment": "0x"
    },
    "primaryType": "Mail",
    "types": {
        "EIP712Domain": [
            {
                "name": "name",
                "type": "string"
            },
            {
                "name": "version",
                "type": "string"
            },
            {
                "name": "chainId",
                "type": "uint256"
            },
            {
                "name": "verifyingContract",
                "type": "address"
            }
        ],
        "Group": [
            {
                "name": "name",
                "type": "string"
            },
            {
                "name": "members",
                "type": "Person[]"
            }
        ],
        "Mail": [
            {
                "name": "from",
                "type": "Person"
            },
            {
                "name": "to",
                "type": "Person[]"
            },
            {
                "name": "contents",
                "type": "string"
            },
            {
                "name": "attachment",
                "type": "bytes"
            }
        ],
        "Person": [
            {
                "name": "name",
                "type": "string"
            },
            {
                "name": "wallets",
                "type": "address[]"
            }
        ]
    }
}

const signatureV4 = await ethereum.request({
  method: 'eth_signTypedData_v4',
  params: [
    accounts[0], 
    JSON.stringify(msgParams)
  ]
});

Event Listeners

The SDK emits events for account and network changes.

accountsChanged

ethereum.on('accountsChanged', (accounts) => {//error handle };

chainChanged

ethereum.on('chainChanged', (chainId) => {//error handle });

To remove listeners:

ethereum.removeListener('accountsChanged', handleAccountsChanged);
// or remove all listeners
ethereum.removeAllListeners();

Last updated