Server wallets are in early access and we'd love to hear how you're using them! Contact us at [email protected] - we'd love to help you get up and running.
Server wallets can be programmatically controlled using access keys. This enables backend applications to sign transactions and messages on behalf of users without requiring interactive authentication.
Get your API key by creating a new app in your Alchemy Dashboard. Make sure your desired network is enabled for your app under the Networks tab.
Generate a secure access key for authentication. This key will never be sent to our servers - we'll derive a public key from it when interacting with Alchemy.
Critical: Save your access key securely!
This access key is required to control your server wallet and cannot be recovered if lost. Make sure to store it in a secure location.
import { generateAccessKey } from "@account-kit/signer";
// Generate a random access key
const accessKey = generateAccessKey();
console.log("Access key:", accessKey);
// Store this securely - you'll need it to control the server signerBefore we can send transactions we need a way to sign them. Let's create a server signer using the access key you just created to handle this:
import { createServerSigner } from "@account-kit/signer";
const signer = await createServerSigner({
auth: {
accessKey: "your-access-key-here",
},
connection: {
apiKey: "your-alchemy-api-key",
},
});
console.log("Signer address:", await signer.getAddress());Want to use the same access key to control multiple server signers? Check out
the example below to learn how to use auth.accountId to create multiple
signers that you can control with the same access key.
Multiple signers per access key
import { createServerSigner } from "@account-kit/signer";
const businessSigner = await createServerSigner({
auth: {
accessKey: "your-access-key-here",
accountId: "business",
},
connection: {
apiKey: "your-alchemy-api-key",
},
});
const personalSigner = await createServerSigner({
auth: {
accessKey: "your-access-key-here", // same access key
accountId: "personal", // different account ID
},
connection: {
apiKey: "your-alchemy-api-key",
},
});
// These will have different addresses despite using the same access key
console.log("Business address:", await businessSigner.getAddress());
console.log("Personal address:", await personalSigner.getAddress());We can now send transactions using the Smart Account Client:
import { createSmartWalletClient } from "@account-kit/wallet-client";
import { alchemy, baseSepolia } from "@account-kit/infra";
// Create Smart Account Client using the signer from Step 2
const client = createSmartWalletClient({
transport: alchemy({
apiKey: "your-alchemy-api-key",
}),
chain: baseSepolia,
signer,
policyId: "your-sponsor-gas-policy-id", // Make sure enabled on Base Sepolia
});
// Retrieve account
const account = await client.requestAccount();
console.log("Smart account address:", account.address);
// Send a transaction
const { id } = await client.sendCalls({
calls: [
{
to: "0x1234567890123456789012345678901234567890",
value: "0x0",
data: "0x",
},
],
from: account.address,
});
console.log("Transaction sent:", id);Server wallet can also easily be used on Solana. To start sending sponsored transactions on Solana, set up a Solana sponsor gas policy in our dashboard and follow the guide below.
import { createServerSigner } from "@account-kit/signer";
import { Connection, SystemProgram, PublicKey } from "@solana/web3.js";
// Set up Solana connection
const connection = new Connection(
`https://solana-devnet.g.alchemy.com/v2/your-alchemy-api-key`,
);
const signer = await createServerSigner({
auth: { accessKey: "your-access-key" },
connection: { apiKey: "your-alchemy-api-key" },
});
// Convert the signer to a Solana-compatible signer
const solanaSigner = signer.toSolanaSigner();
// Build transaction instructions
const instructions = [
SystemProgram.transfer({
fromPubkey: new PublicKey(solanaSigner.address),
toPubkey: new PublicKey(solanaSigner.address),
lamports: 0,
}),
];
// Add sponsorship
const tx = await solanaSigner.addSponsorship(
instructions,
connection,
"your-solana-sponsorship-policy-id", // Make sure enabled on Solana devnet
);
// Sign the transaction
await solanaSigner.addSignature(tx);
// Send the transaction
const hash = await connection.sendTransaction(tx);
console.log("Transaction sent:", hash);