Solana Interactions
Send a Versioned Solana Transaction
Configurations
- Installing Dynamic
- Chains/Networks
- Authentication
- Wallets
- Set Up Embedded Wallets
- Set Up Global Connectivity
- Set Up Branded Wallets
- Add Account Abstraction
- Using Wallets
- Accessing Wallets
- Interacting with wallets
- General Interactions
- EVM Interactions
- Bitcoin Interactions
- Solana Interactions
- Multi Wallet
- Multi Asset UI
- Send Balance UI
- Users / VC's
- Design
- Headless
- Onramps
- Bridges
Developer Dashboard
- SDK and API Keys
- Sandbox vs Live
- Analytics
- User Management
- Settings
- Admin
- Webhooks
- Configuring Social Providers
Tutorials
- Farcaster
- Features
- Frameworks
- Integrations
- Webhooks
Migrating to Dynamic
- Migrating to Dynamic
- Migration Tutorials
SDKs
- React SDK
Troubleshooting
- Dynamic Doctor
- React Issues
- NextJS Issues
- Wallet Issues
- WalletConnect Issues
- Solved Issues
Solana Interactions
Send a Versioned Solana Transaction
import { ISolana, isSolanaWalet } from '@dynamic-labs/solana-core';
import { Connection } from "@solana/web3.js";
const { primaryWallet } = useDynamicContext();
if(!isSolanaWalet(primaryWallet)) {
return;
}
const connection: Connection = await primaryWallet.getConnection();
const fromKey = new PublicKey(primaryWallet.address);
const toKey = new PublicKey(address);
const amountInLamports = Number(amount) * 1000000000;
const instructions = [
SystemProgram.transfer({
fromPubkey: fromKey,
lamports: amountInLamports,
toPubkey: toKey,
}),
];
const blockhash = await connection.getLatestBlockhash();
// create v0 compatible message
const messageV0 = new TransactionMessage({
instructions,
payerKey: fromKey,
recentBlockhash: blockhash.blockhash,
}).compileToV0Message();
const transferTransaction = new VersionedTransaction(messageV0);
const signer: ISolana = await primaryWallet.getSigner();
await signer
.signAndSendTransaction(transferTransaction)
.then((res: any) => {
console.log(
`Transaction successful: https://solscan.io/tx/${res.signature}?cluster=devnet`,
);
})
.catch((reason: any) => {
console.error(reason);
});
Was this page helpful?