Solana Interactions
Send Solana Legacy Transaction
Configurations
- Installing Dynamic
- Chains/Networks
- Authentication
- Wallets
- Setup Embedded Wallets
- Setup Branded Wallets
- Add Account Abstraction
- Using Wallets
- Accessing Wallets
- Connecting Wallets
- Interacting with wallets
- General Interactions
- EVM Interactions
- Bitcoin Interactions
- Solana Interactions
- Multi Asset 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
Troubleshooting
- Dynamic Doctor
- React Issues
- NextJS Issues
- Wallet Issues
- WalletConnect Issues
- Solved Issues
Solana Interactions
Send Solana Legacy Transaction
// for external wallets only, use IEmbeddedWalletSolanaSigner for Solana embedded wallets
import { ISolana } from '@dynamic-labs/solana';
const { primaryWallet } = useDynamicContext();
import { Connection } from '@solana/web3.js';
const connection = await (
primaryWallet as any
).connector.getPublicClient<Connection | undefined>();
if (!connection) return;
const fromKey = new PublicKey(primaryWallet.address);
const toKey = new PublicKey(address);
const amountInLamports = Number(amount) * 1000000000;
const transferTransaction = new Transaction().add(
SystemProgram.transfer({
fromPubkey: fromKey,
lamports: amountInLamports,
toPubkey: toKey,
}),
);
const blockhash = await connection.getLatestBlockhash();
transferTransaction.recentBlockhash = blockhash.blockhash;
transferTransaction.feePayer = fromKey;
const signer = await (primaryWallet as any).connector.getSigner<ISolana>();
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?