Solana Interactions
Typed Solana signer
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
Typed Solana signer
Here are some examples on how to use the Solana typed signer
Example for Solana embedded Wallet
import { IEmbeddedWalletSolanaSigner, isSignedMessage } from '@dynamic-labs/solana';
const App = () => {
const { primaryWallet } = useDynamicContext();
const signMessage = async () => {
if (!primaryWallet) return;
const signer = await primaryWallet.connector.getSigner<IEmbeddedWalletSolanaSigner>();
if (!signer) return;
const signedMessage = await signer.signMessage(
new TextEncoder().encode('example'),
);
if (!signedMessage) return;
const signature: Uint8Array = isSignedMessage(signedMessage)
? signedMessage.signature
: signedMessage;
}
...
}
Example for any external Solana wallet and Backpack wallet
import { ISolana, isSignedMessage } from '@dynamic-labs/solana';
const App = () => {
const { primaryWallet } = useDynamicContext();
const signMessage = async () => {
if (!primaryWallet) return;
const signer = await primaryWallet.connector.getSigner<ISolana>();
if (!signer) return;
const signedMessage = await signer.signMessage(
new TextEncoder().encode('example'),
);
if (!signedMessage) return;
const signature: Uint8Array = isSignedMessage(signedMessage)
? signedMessage.signature
: signedMessage;
}
...
}
Example for Solana common wallets
import { ISolanaSigner } from '@dynamic-labs/solana';
const App = () => {
const { primaryWallet } = useDynamicContext();
const signMessage = async () => {
if (!primaryWallet) return;
const signer = await primaryWallet.connector.getSigner<ISolanaSigner>();
if (!signer) return;
const signedMessage = await signer.signMessage(
new TextEncoder().encode('example'),
);
if (!signedMessage) return;
const signature: Uint8Array = signedMessage.signature
}
...
}
Example for Backpack wallet only
import { IBackpackSolanaSigner } from '@dynamic-labs/solana';
const App = () => {
const { primaryWallet } = useDynamicContext();
const signMessage = async () => {
if (!primaryWallet) return;
const signer = await primaryWallet.connector.getSigner<IBackpackSolanaSigner>();
if (!signer) return;
const signature: Uint8Array | void = await signer.signMessage(
new TextEncoder().encode('example'),
);
}
...
}
Example using isBackpackSolanaSigner type guard function
import { ISolana, isBackpackSolanaSigner } from '@dynamic-labs/solana';
const App = () => {
const { primaryWallet } = useDynamicContext();
const signMessage = async () => {
if (!primaryWallet) return;
const signer = await primaryWallet.connector.getSigner();
if (isBackpackSolanaSigner(signer)) {
const signature: Uint8Array | void = await signer.signMessage(
new TextEncoder().encode('example'),
);
}
}
...
}
Was this page helpful?