Skip to content
Alchemy Logo

Solana sponsorship

Use Solana sponsorship to cover transaction fees and rent for Solana calls submitted through @alchemy/wallet-apis.

Use paymaster on the smart wallet client to apply a Solana sponsorship policy to all sendCalls and prepareCalls requests from that client.

sendCalls.ts
import { client } from "./client.ts";
import { transferSolCall } from "./utils.ts";
 
const { id } = await client.sendCalls({
  calls: [
    transferSolCall({
      from: client.solanaAccount,
      to: client.solanaAccount,
      lamports: 0n,
    }),
  ],
});
 
const result = await client.waitForCallsStatus({ id });
 
console.log(result);

Per-request policy

Pass capabilities.paymaster to override the client-level policy for a single sendCalls or prepareCalls request. Request-level capabilities.paymaster.policyId takes priority over the client-level policy.

sponsor-solana-request.ts
import { client } from "./client.ts";
import { transferSolCall } from "./utils.ts";
 
const { id } = await client.sendCalls({
  calls: [
    transferSolCall({
      from: client.solanaAccount,
      to: client.solanaAccount,
      lamports: 0n,
    }),
  ],
  capabilities: {
    paymaster: {
      policyId: "OTHER_SOLANA_POLICY_ID",
    },
  },
});
 
const result = await client.waitForCallsStatus({ id });
Rent sponsorship

Solana sponsorship can also cover rent for account creation.

Top-level rent sponsorship applies automatically when a sponsored transaction includes top-level SystemProgram.createAccount or Associated Token Program Create / CreateIdempotent instructions. No extra request parameter is required for those top-level instructions.

For accounts created inside a cross-program invocation (CPI), opt in per request with prefundRent: true. This asks the service to simulate the transaction, estimate the CPI rent requirement, and prefund the user's wallet before the transaction is submitted. See CPI rent prefunding for the full contract, requirements, and best practices.

sponsor-solana-cpi-rent.ts
import { client, config } from "./client.ts";
import { transferSolCall } from "./utils.ts";
 
const { id } = await client.sendCalls({
  calls: [
    transferSolCall({
      from: client.solanaAccount,
      to: client.solanaAccount,
      lamports: 0n,
    }),
  ],
  capabilities: {
    paymaster: {
      policyId: config.policyId,
      prefundRent: true,
    },
  },
});
 
const result = await client.waitForCallsStatus({ id });

CPI rent prefunding is allowlisted. Contact support@alchemy.com to request access. Policies used with prefundRent must set maxSpendPerTxnUsd, and the transaction payer must be the user's wallet: the same account your program's CPI will debit for rent.

If you are not using the Wallet APIs client and need to sponsor a serialized Solana transaction directly, use the lower-level alchemy_requestFeePayer flow.

Build more:

Troubleshooting:

Was this page helpful?