import { ChipiBrowserSDK } from "@chipi-stack/backend";
const browserClient = new ChipiBrowserSDK({
apiPublicKey: process.env.VITE_CHIPI_PUBLIC_KEY, // or your framework's env var
});
async function createUserWallet(userId: string, userPin: string) {
try {
const bearerToken = await getBearerToken(); // Your auth implementation
const newWallet = await browserClient.createWallet({
params: {
encryptKey: userPin,
externalUserId: userId,
},
bearerToken: bearerToken,
});
console.log('Wallet created successfully!');
console.log('Address:', newWallet.wallet.publicKey);
console.log('Deployment TX:', newWallet.txHash);
// Store wallet data in your app state
saveWalletToState({
userId,
publicKey: newWallet.wallet.publicKey,
encryptedPrivateKey: newWallet.wallet.encryptedPrivateKey,
deploymentTxHash: newWallet.txHash,
});
return newWallet;
} catch (error) {
console.error('Wallet creation failed:', error);
throw error;
}
}
// Usage example
async function onboardNewUser(userId: string, pin: string) {
const wallet = await createUserWallet(userId, pin);
// Verify deployment on StarkScan
const contractUrl = `https://starkscan.co/contract/${wallet.wallet.publicKey}`;
console.log('View contract:', contractUrl);
return wallet;
}