SDK

Withdraw

Withdraw assets from Aztec to Ethereum.

Use the WithdrawController to withdraw assets from Aztec to Ethereum.

You can find the interface of the WithdrawController here.

Controller Setup

AztecSdk.createWithdrawController(
    userId: GrumpkinAddress, 
    userSigner: Signer, 
    value: AssetValue, 
    fee: AssetValue, 
    to: EthAddress)
        : Promise<WithdrawController>

Inputs

ArgumentsTypeDescription
userIdGrumpkinAddressThe Aztec account to make the withdrawal from.
userSignerSignerA signer for the provided userId.
valueAssetValueThe asset type and amount to withdraw.
feeAssetValueThe asset type and amount to pay for the Aztec transaction fee.
toEthAddressThe Ethereum address to send the funds on Ethereum.

Returns

Return TypeDescription
WithdrawControllerA user instance with apis bound to the user's account id.

Fees

Fees for withdrawals are calculated using a similar method as for registrations, deposits and transfers, but using the getWithdrawalFees method.

getWithdrawalFees has a second optional options argument.

interface GetFeeOptions {
    userId?: GrumpkinAddress;
    userSpendingKeyRequired?: boolean;
    excludePendingNotes?: boolean;
    feeSignificantFigures?: number;
} & { recipient?: EthAddress; assetValue?: AssetValue }

recipient?: EthAddress is used to check if the recipient address is a contract wallet, for which the fees are higher.

The settlement time is inferred from the fee a user pays, it is not explicitly sent to the controller.

Executing a Withdrawal

A withdrawal setup and execution looks like this:

const tokenAssetId = sdk.getAssetIdByAddress(tokenAddress);

const tokenAssetValue = { assetId: tokenAssetId, value: tokenQuantity };

// optional fee options
// not relevant if using FeeController
const feeOptions = {
    userId: aztecPublicKey,
    userSpendingKeyRequired: true,
    excludePendingNotes: true,
    feeSignificantFigures: 2,
    assetValue: tokenAssetValue,
    recipient: ethAddress
}

const tokenWithdrawFee = (await sdk.getWithdrawFees(tokenAssetId, feeOptions))[settlementTime];

const tokenWithdrawController = sdk.createWithdrawController(
    user,
    signer,
    tokenAssetValue,
    tokenWithdrawFee,
    recipientEthereumAddress
);

await tokenWithdrawController.createProof();
let txId = await tokenWithdrawController.send();

Once the transaction is sent, you just have to wait for the rollup to settle on Ethereum and the Rollup processor contract will send the funds.

Previous
Transfer
Next
Types