Solana Provider
Request data and signatures from Solana wallets
Solana Providers are a Wallet Standard compliant Provider object. Used by the Solana JavaScript SDK, the Provider object contains details of connected wallets and exposes methods for signing and sending messages and transactions. The most frequently supported methods include:
provider.signMessage(message)
- Sign a message with the connected walletprovider.signTransaction(transaction)
- Sign a transaction with the connected walletprovider.sendTransaction(transaction, connection, options)
- Send a transaction to a specified Solana connectionprovider.on(event, callback)
- Subscribe to events like account or connection changesprovider.removeListener(event, callback)
- Remove subscriptions added byprovider.on
Here are some examples of using the provider
:
1function async signData() {2 const dataToSign = 'Hello World';3 const inputArray = new TextEncoder().encode(dataToSign);4 5 // plaidProvider returned earlier from Wallet Onboard6 const result = await plaidProvider.signMessage(inputArray);7 return result;8}
1import { SystemProgram, Transaction, Connection } from '@solana/web3.js';23function async sendTransaction() {4 const publicKey = plaidProvider.publicKey;5 const toPubKey = destination; // destination public key67 const transaction = new Transaction().add(8 SystemProgram.transfer({9 fromPubkey: publicKey,10 lamports: 1000000,11 toPubkey,12 }),13 );1415 const connection = new Connection('https://api.devnet.solana.com', 'confirmed');16 const {17 context: { slot: minContextSlot },18 value: { blockhash, lastValidBlockHeight },19 } = await connection.getLatestBlockhashAndContext();2021 const signature = await plaidProvider.sendTransaction(transaction, connection, { minContextSlot });22 await connection.confirmTransaction({ blockhash, lastValidBlockHeight, signature });23}
For more documentation on the available methods, see the Solana docs.