Skip to main content

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 withrawal 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 argument reciepient?: EthAddress. This 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 tokenWithdrawFee = (await sdk.getWithdrawFees(tokenAssetId))[settlementTime];

const tokenAssetValue = { assetId: tokenAssetId, value: tokenQuantity };
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.