Import Solana Wallet
Copy 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:
Testnet:
Devnet:
Copy 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.
Copy 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.
Copy 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.
Copy 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.
Copy 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.
Copy const account = await solanaWallet.createAccount()
Recover account
solanaWallet .importAccount( privateKey : string ) => Promise< Wallet >
Recover account from private key string and returns Wallet object.
Copy 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.
Copy 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).
Copy 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.
Copy 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.
Copy const tx = await solanaWallet.transferToken(tokenAddress, recipient, amount)
Get provider
solanaWallet .getProvider( rpcUrl : string ) => Connection
Get solana provider (Connection) from RPC url.
Copy const provider = solanaWallet.isContractAddress(rpcUrl)
Get transaction
solanaWallet .getTransaction( hash : string ) => Promise< TransactionResponse | null >
Get transaction object from tx hash.
Copy 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.
Copy const tokenList = await solanaWallet.getTokenList(cluster)