EVM Provider

The Tomo Telegram SDK implements the Ethereum provider, allowing seamless integration with existing Ethereum-compatible DApps.

To use the EVM provider in your application, you need to first install the SDK and get the wallet provider:

// get provider 
const ethereum = window.ethereum;

Below are methods that developers can use with our EVM provider.

Wallet Connect

Before using the provider, the user needs to log in to the wallet through the modal by eth_requestAccounts method. The isConnected method returns a boolean value indicating whether the wallet is connected or not.

ethereum.isConnected(): boolean

Query Methods

The request method is used to make an RPC request to the connected wallet. For detailed information on JSON-RPC methods, refer to:

We provide some frequently used methods as below:

Get accounts address

Connects to the wallet and returns the address of the connected wallet. In Tomo, the return value is the first address in the response.

Or you can use the eth_accounts method to fetch the previous read address from the cache. If missed, it will return an empty array; use it with care!

Get chain ID

Returns the chain ID of the connected wallet.

Get balance

Returns the mainnet balance of ETH in wei of hex format.

Sign Message

The Tomo Telegram SDK supports signing messages through the request method under the Metamask standard:

  • personal_sign

  • eth_signTypedData

  • eth_signTypedData_v3

  • eth_signTypedData_v4

The return value is the signature data. For detailed usage, refer to:

Example of⁣personal_sign:

Example of⁣eth_signTypedData_v4:

Sign Transaction

eth_signTransaction method will return a response with a signed transaction. Or you can use eth_sendTransaction it to send the signed transaction directly to the RPC node you specified in the provider. If you specify the chainId in params, the transaction will be sent to that network. Otherwise, it will be sent to the network you switched to using wallet_switchEthereumChain the method.

For users to verify the transaction contents, we only support passing parameters to the SDK and letting the user decide whether to sign the created transaction.

Transfer transaction

Contract call transaction

For example, below is the demo for sending ERC20 tokens:

Check this doc for more usages.

Send Signed Transaction

To send a signed transaction, the user must use another library, like

Switch Ethereum Chain​

Switches the connected wallet to the specified chain ID.

Event Listeners

The SDK emits events for account and network changes.

accountsChanged

chainChanged

To remove listeners:

Last updated