Cancel a Subscription and Withdraw Funds
Cancelling a Chainlink Functions subscription and withdrawing its remaining LINK balance is a single onchain transaction: calling cancelSubscription deletes the subscription, removes all associated consumers, and transfers the remaining balance in one call. Only the subscription owner can perform this action.
Prerequisites
- Your Subscription ID. If you don't know it, see Find your Subscription ID below.
- The FunctionsRouter address for the network your subscription is on. Find it in the Supported Networks reference.
- No in-flight requests. A subscription cannot be canceled while it has pending requests. Any request that has been pending for longer than five minutes must first be timed out.
- A wallet you can sign transactions with using the subscription owner address. The examples below use Foundry's
castwith a raw private key, but you can substitute a keystore or Ledger. See Sending Transactions in the Foundry docs for the equivalent--accountor--ledgerflags.
Find your Subscription ID
If you already know your Subscription ID, skip to Cancel the subscription and withdraw funds.
- Using the Subscription Manager: Go to the Chainlink Functions Subscription Manager, connect the owner wallet, and open the subscription under My Subscriptions. The Subscription ID is shown on the subscription's detail page.
- Using the lookup spreadsheet: If you no longer have access to the owner wallet's session or the subscription isn't showing in the app, look up your Subscription ID by owner address in the Chainlink Functions Subscription ID Registry.
Cancel the subscription and withdraw funds
Call cancelSubscription on the FunctionsRouter contract, passing your Subscription ID and the address that should receive the remaining LINK balance:
cast send FUNCTIONS_ROUTER_ADDRESS \
"cancelSubscription(uint64,address)" \
SUBSCRIPTION_ID \
TO_ADDRESS \
--rpc-url $CHAIN_RPC_URL \
--private-key $PRIVATE_KEY
Where:
FUNCTIONS_ROUTER_ADDRESSis the address of the FunctionsRouter contract for your network.SUBSCRIPTION_IDis your numerical Subscription ID.TO_ADDRESSis the wallet address that should receive the withdrawn LINK.CHAIN_RPC_URLis the HTTP RPC URL for your network.
Once this transaction confirms, the Subscription ID is deleted, all consumers are removed, and the remaining LINK balance is transferred to TO_ADDRESS.