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.
The isConnected
method returns a boolean value indicating whether the wallet is connected or not.
Copy ethereum .isConnected (): boolean
The request
method is used to make an RPC request to the connected wallet.
Copy 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:
Connects to the wallet and returns the address of the connected wallet.
Copy const accounts = await ethereum .request ({ method : 'eth_requestAccounts' });
Returns the address of the connected wallet.
Copy const accounts = await ethereum .request ({ method : 'eth_accounts' });
Returns the chain ID of the connected wallet.
Copy const chainId = await ethereum .request ({ method : 'eth_chainId' });
wallet_switchEthereumChain Switches the connected wallet to the specified chain ID.
Copy try {
await ethereum .request ({
method : 'wallet_switchEthereumChain' ,
params : [{ chainId : '0xf00' }] ,
});
} catch (switchError) {
// error handle
}
Sends a transaction to the connected wallet.
For detailed usage, refer to:
Copy
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]
});
The Tomo Telegram SDK supports various signing methods under Metamask standard:
For detailed usage, refer to:
Example of personal_sign
:
Copy 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
:
Copy
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)
]
});
The SDK emits events for account and network changes.
accountsChanged
Copy ethereum .on ( 'accountsChanged' , (accounts) => { //error handle };
chainChanged
Copy ethereum .on ( 'chainChanged' , (chainId) => { //error handle });
To remove listeners:
Copy ethereum .removeListener ( 'accountsChanged' , handleAccountsChanged);
// or remove all listeners
ethereum .removeAllListeners ();