Solana

This page guides to create and use Solana Wallet instance in multichain-wallet-sdk.

Import Solana Wallet

import { SolanaWallet } from  'multichain-wallet-sdk';

Reference

Create wallet SDK instance

class SolanaWallet(rpcUrl: string)

Pass RPC endpoint and create new wallet SDK instance. RPC endpoints Mainnet: https://api.mainnet-beta.solana.com Testnet: https://api.testnet.solana.com Devnet: https://api.devnet.solana.com

const solanaWallet = new SolanaWallet("https://api.mainnet-beta.solana.com")

Initialize SDK instance

solanaWallet.initialize(privateKey?: string) => Promise<void>

Initialize SDK and create primary wallet with give private key or random generated one.

await solanaWallet.initialize()

Create new wallet

solanaWallet.createWallet(derivedPath?: string) => Promise<Wallet>

Create random wallet (address, privateKey, mnemonic, nonce) and returns it as Wallet object. Without passing derivedPath argument, default solana HD wallet will be generated.

const wallet = await solanaWallet.createWallet()

Recover wallet

solanaWawllet.recoverWallet(mnemonic: string, derivedPath?: string) => Promise<Wallet>

Recover wallet from mnemonic and derived path arguments and returns it as Wallet object. Without passing derivedPath argument, SDK will generate standard solana HD wallet.

const wallet = await solanaWallet.recoverWallet("...12 word phrases...")

Get key pair from private key

solanaWallet.getKeyPairFromPrivateKey(privateKey: string) => KeyPair

Create key pair of private key <=> public key from private key.

const keyPair = solanaWallet.getKeyPairFromPrivateKey(privateKey)

Create account

solanaWallet.createAccount(derivedPath?: string) => Promise<Wallet>

Create random account from based on derived path or solana default path returns Wallet object.

const account = await solanaWallet.createAccount()

Recover account

solanaWallet.importAccount(privateKey: string) => Promise<Wallet>

Recover account from private key string and returns Wallet object.

const account = await solanaWallet.importAccount(privateKey)

Get SOL balance

solanaWallet.getBalance(address: string, tokenAddress?: string) => Promise<number>

Get native coin or SPL token balance of account or given address.

const balance = await solanaWallet.getBalance(address)

Get token detail

solanaWallet.getTokenInfo(cluster: 'mainnet-beta' | 'testnet' | 'devnet', address: string) => Promise<ITokenInfo | null>

Get detail info of SPL token ITokenInfo object or null(If inputted address is not token address).

const detail = await solanaWallet.getTokenInfo(cluster, tokenAddress)

Send payment transaction

solanaWallet.sendSol(recipient: string, amount: number, privateKey?: string) => Promise<TransactionResponse | null>

Send native currency by create, sign, and broadcast payment transaction and returns executed transaction response object.

const tx = await solanaWallet.sendSol(recipientAddress, amount)

Transfer token

solanaWallet.transferToken(tokenAddress: string, recipient: string, amount: number, privateKey?: string) => Promise<TransactionResponse | null>

Transfer given amount of SPL token to recipient and returns executed transaction response object.

const tx = await solanaWallet.transferToken(tokenAddress, recipient, amount)

Get provider

solanaWallet.getProvider(rpcUrl: string) => Connection

Get solana provider (Connection) from RPC url.

const provider = solanaWallet.isContractAddress(rpcUrl)

Get transaction

solanaWallet.getTransaction(hash: string) => Promise<TransactionResponse | null>

Get transaction object from tx hash.

const tx = await solanaWallet.getTransaction(hash)

Get token list

solanaWallet.getTokenList(cluster: 'mainnet-beta' | 'testnet' | 'devnet') => Promise<Array<ISplTokenInfo>>

Get existing SPL token list of selected network.

const tokenList = await solanaWallet.getTokenList(cluster)

Last updated