Solana Provider
The Tomo Telegram SDK provides a Solana Provider for querying and sending SOL and SPL tokens.
// get provider
const sol = window.tomo_sol;
Connect with the Wallet
Before using the provider, the user needs to log in to the wallet through the modal by following the method:
// connect wallet
await sol?.connectWallet();
Query Methods
Solana providers support two query methods:
getAddress
getBalance
const address = sol.getAddress();
const balance = await sol.getBalance(address);
Signing Methods
In Solana providers, we provide four signing methods:
signMessage
signTransaction
signTransactions
signTokenTransaction
Sign message
signMessage
the method will create an offchain signature for one message and return the signed transaction in hex.
const response = await sol.signMessage(signMsg);
To verify the signature, you need to add the header "\xffsolana offchain" before the `signMsg`
SOL transfer transaction
signTransaction
is typically used to send SOL to another address and return the signed transaction. You can also use signTransactions
it to pass an array of transactions for signing.
const response = await sol.signTransaction({
from: 8y9wmwVhban5Mrp8j68fQv1Kceeifeowt5Yw1DjwXoxk,
to: 646rZ228LDcYecNvoBGNysJ9pGLc7gBeTrnSgZ476rBp,
value: 0.01,
});
SPL token transaction
and signTokenTransaction
supports signing transactions for sending SPL tokens. You need to provide a mint address for this transaction.
const response = await sol.signTokenTransaction({
from: '8y9wmwVhban5Mrp8j68fQv1Kceeifeowt5Yw1DjwXoxk',
to: '646rZ228LDcYecNvoBGNysJ9pGLc7gBeTrnSgZ476rBp',
value: val,
chainId: 501,
contract: 'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB',
});
Sending Methods
After signing transactions, you can use sendTransaction
it to send the transaction. The return value is the transaction hash:
const res = await sol.sendTransaction(response);
Last updated