Solana Provider

After setting up your wallet, you can have access to the Solana provider:

// react
const { providers } = useTomo()
const { solanaProvider } = providers;

// pure js
const solanaProvider = window.tomo_sol

Get Solana Address

the Solana address from the wallet state or provider. In React framework:

// get address from wallet state
const { walletState } = useTomo()
const solanaAddress = walletState.solanaAddress

// or get address from provider
const { providers } = useTomo()
const solanaAddress = await providers.solanaProvider.getAddress()

Or Pure JS:

/** pure js */
import { getWalletState } from '@tomo-inc/tomo-web-sdk';
// get from wallet state
const walletState = getWalletState()
const solanaAddress = walletState.solanaAddress

// or get from provider
const solanaAddress = await window.tomo_sol.getAddress()

Provider Functions

providers.solanaProvider exposes three functions for sending requests to the user's wallet:

Signing a Message

It uses the Solana provider to sign a plain text offchain message, which returns the signature of the given message with the message header.

Sign Transaction

Given a transaction in the format of Transaction from @solana/web3.js you can use signTransactionmethod to get the signed transaction in hex value if the user approves the request.

Send Transaction

You can also send the transaction directly through this sendTransaction method. The return value is the transaction signature if signed and sent correctly.

Example

We provide an example as follows:

React

Pure JavaScript

Last updated