Solana's Token Programs support delegation—granting another account permission to transfer tokens from your token account up to a specified limit. This enables use cases like automated payments, escrow services, and third-party payment processing without giving up custody of your funds.
How Delegation Works
When you approve a delegate, you're authorizing a specific account to transfer tokens on your behalf:
- Owner retains custody: You still own the tokens and can transfer or revoke at any time
- Capped spending: The delegate can only transfer up to the approved amount
- Single delegate per account: Each token account can only have one active delegate
- New approval replaces old: Approving a new delegate automatically revokes the previous one
Delegation is non-custodial. The delegate can spend tokens up to the limit, but cannot access or drain the account beyond the approved amount. The owner can revoke at any time.
Business Use Cases
| Use Case | How Delegation Helps |
|---|---|
| Payment processors | Merchant grants processor permission to settle transactions |
| Automated payroll | Treasury approves payroll service to disburse salaries |
| Escrow services | Buyer delegates to escrow agent for conditional release |
| Trading platforms | User approves exchange to execute trades on their behalf |
| Card issuance | User approves card issuer to charge purchases to their token account |
Approving a Delegate
Grant another account permission to spend tokens from your account:
import { getApproveCheckedInstruction } from "@solana-program/token";// Approve delegate to spend up to 1,000 USDC (6 decimals)const approveInstruction = getApproveCheckedInstruction({source: tokenAccountAddress, // Your token accountmint: usdcMintAddress, // USDC mintdelegate: delegateAddress, // Account receiving permissionowner: ownerKeypair, // You (must sign)amount: 1_000_000_000n, // 1,000 USDC in base unitsdecimals: 6});
Parameters:
source: The token account granting permissiondelegate: The account that will have spending permissionowner: Current owner of the token account (must sign the transaction)amount: Maximum tokens the delegate can transferdecimals: Token decimals for validation (prevents decimal errors)
Revoking a Delegate
Remove all spending permissions from the current delegate:
import { getRevokeInstruction } from "@solana-program/token";const revokeInstruction = getRevokeInstruction({source: tokenAccountAddress, // Your token accountowner: ownerKeypair // You (must sign)});
Revoke removes all delegate permissions—there's no partial revoke. If you need to reduce the limit, approve the same delegate with a lower amount.
Checking Delegation Status
Query a token account to see its current delegate and remaining allowance:
import { fetchToken } from "@solana-program/token";const tokenAccount = await fetchToken(rpc, tokenAccountAddress);if (tokenAccount.data.delegate) {console.log("Delegate:", tokenAccount.data.delegate);console.log("Remaining allowance:", tokenAccount.data.delegatedAmount);} else {console.log("No delegate set");}
Transferring as a Delegate
When acting as the delegate, use a standard transfer but sign with the delegate keypair instead of the owner:
import { getTransferCheckedInstruction } from "@solana-program/token";const transferInstruction = getTransferCheckedInstruction({source: ownerTokenAccount, // The account you have permission to spend frommint: usdcMintAddress,destination: recipientTokenAccount,authority: delegateKeypair, // You (the delegate) sign, not the owneramount: 100_000_000n, // 100 USDCdecimals: 6});
The transfer will succeed if:
- The source account has sufficient balance
- The delegate signs the transaction
Each transfer reduces the remaining allowance. When the allowance reaches zero, the delegate can no longer transfer tokens.
Security Considerations
For account owners:
- Only approve trusted delegates
- Set the minimum necessary spending limit
- Revoke delegations when no longer needed
- Monitor your accounts for unexpected transfers
For service providers (delegates):
- Clearly communicate the requested spending limit to users
- Implement proper key management for your delegate account
- Track allowance consumption to request re-approval before limits are exhausted
Delegation vs. Custody
| Aspect | Delegation | Full Custody |
|---|---|---|
| Token ownership | User retains | User transfers to custodian |
| Spending control | Capped at approved amount | Full access to transferred funds |
| Revocation | Instant, by owner | Requires custodian cooperation |
| Risk exposure | Limited to approved amount | Entire balance |
| Trust required | Limited | High |
Delegation provides a middle ground—enabling automated payments while limiting risk exposure to the approved amount.
Related Resources
- Approve Delegate — Technical details on the approve instruction
Is this page helpful?