import { DynamicSvmWalletClient } from '@dynamic-labs-wallet/node-svm';
import { ThresholdSignatureScheme } from '@dynamic-labs-wallet/node';
// Create authenticated client
export const authenticatedSvmClient = async () => {
const client = new DynamicSvmWalletClient({
environmentId: process.env.DYNAMIC_ENVIRONMENT_ID!,
});
await client.authenticateApiToken(process.env.DYNAMIC_AUTH_TOKEN!);
return client;
};
export const createSvmWallet = async ({
thresholdSignatureScheme = ThresholdSignatureScheme.TWO_OF_TWO,
password,
onError
}: {
thresholdSignatureScheme?: ThresholdSignatureScheme;
password?: string;
onError?: (error: Error) => void;
}) => {
const svmClient = await authenticatedSvmClient();
const wallet = await svmClient.createWalletAccount({
thresholdSignatureScheme,
password,
onError,
backUpToClientShareService: true,
});
return {
accountAddress: wallet.accountAddress,
rawPublicKey: wallet.rawPublicKey,
walletId: wallet.walletId,
externalServerKeyShares: wallet.externalServerKeyShares,
};
};
// Usage example
const wallet = await createSvmWallet({
thresholdSignatureScheme: ThresholdSignatureScheme.TWO_OF_TWO,
password: 'your-secure-password',
onError: (error: Error) => {
console.error('SVM wallet creation error:', error);
},
});
console.log('Solana wallet created:', wallet.accountAddress);
console.log('External server key shares:', wallet.externalServerKeyShares);