Create a Wallet
Generate a Solana keypair for your users.
What You'll Do
Generate a new Solana wallet keypair that can sign transactions and hold assets.
Prerequisites
- Poll SDK installed
- Node.js environment
Create a Keypair
The simplest way to create a wallet is using @solana/web3.js:
typescript
import { Keypair } from "@solana/web3.js";
const wallet = Keypair.generate();
console.log("Public Key:", wallet.publicKey.toBase58());
console.log("Secret Key:", Buffer.from(wallet.secretKey).toString("base64"));From Existing Secret Key
If you have an existing wallet, load it from the secret key:
typescript
import { Keypair } from "@solana/web3.js";
// From base64 string
const secretKeyBase64 = "your-base64-secret-key";
const secretKey = Buffer.from(secretKeyBase64, "base64");
const wallet = Keypair.fromSecretKey(secretKey);
// From byte array
const wallet2 = Keypair.fromSecretKey(Uint8Array.from([...]));Create Wallet Adapter
The SDK requires a wallet adapter interface. Here's a helper function:
typescript
import { Keypair, Transaction, VersionedTransaction } from "@solana/web3.js";
function createWalletAdapter(keypair: Keypair) {
return {
publicKey: keypair.publicKey,
signTransaction: async <T extends Transaction | VersionedTransaction>(
tx: T
): Promise<T> => {
if (tx instanceof Transaction) {
tx.sign(keypair);
}
return tx;
},
signAllTransactions: async <T extends Transaction | VersionedTransaction>(
txs: T[]
): Promise<T[]> => {
txs.forEach((tx) => {
if (tx instanceof Transaction) {
tx.sign(keypair);
}
});
return txs;
},
};
}
const wallet = Keypair.generate();
const walletAdapter = createWalletAdapter(wallet);Initialize SDK with Wallet
Now use the wallet adapter with the SDK:
typescript
import { SDK } from "@solworks/poll-sdk";
import { Connection } from "@solana/web3.js";
const connection = new Connection("https://api.devnet.solana.com");
const sdk = SDK.build({
connection,
wallet: walletAdapter,
});Security Notes
- Never expose secret keys in client-side code
- Store keys securely using encryption or key management services
- Use hardware wallets for production applications when possible
- Backup keys before using in production
What Happens
When you create a wallet:
1. A new Ed25519 keypair is generated
2. The public key becomes the wallet's address
3. The secret key is used to sign transactions
4. The wallet starts with zero balance
Next Steps
Your wallet needs SOL for transaction fees and USDC for betting. Continue to the next guide to fund your wallet.