SDK

Transfer

Transfer asset notes on the Aztec network.

Use the TransferController to spend notes (assets) within the Aztec rollup.

You can find the type definition of the TransferController class here.

Controller Setup

AztecSdk.createTransferController(
    userId: GrumpkinAddress, 
    userSigner: Signer, 
    value: AssetValue, 
    fee: AssetValue, 
    recipient: GrumpkinAddress, 
    recipientSpendingKeyRequired?: boolean)
        : Promise<TransferController>;

Inputs

ArgumentsTypeDescription
userIdGrumpkinAddressCurrent owner of the asset note (the sender).
userSignerSignerA signer for the sending account.
valueAssetValueAsset type and amount to send.
feeAssetValueAsset type and amount to pay for the Aztec transaction fee.
recipientGrumpkinAddressPublic key of the receiving account.
recipientSpendingKeyRequired?booleanOptional flag to ensure that the recipient has registered an account. Defaults to true.

Returns

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

Get Asset Id

The SDK includes a utility function to get the the AssetId (assetId: number) from the Ethereum token address. When sending Ether, you can specify the 0x0 address as EthAddress.ZERO.

const assetId = sdk.getAssetIdByAddress(tokenAddress);
const zkETH = sdk.getAssetIdByAddress(EthAddress.ZERO);

Transfer fees

You calculate transfer fees similar to how it is done with registrations or deposits, but there is an additional options object where you can pass additional information to get a more specific fee quote.

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

const tokenTransferFee = (await sdk.getTransferFees(assetId, feeOptions))[settlementTime];

Where settlementTime is TxSettlementTime.INSTANT or TxSettlementTime.NEXT_ROLLUP. INSTANT settlement is faster, but more expensive. NEXT_ROLLUP will wait until the rollup is filled with transactions and then is posted to Ethereum.

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

Create Proof & Send

Once the TransferController is created, you can create a proof and send the transaction with:

await tokenTransferController.createProof();
await tokenTransferController.send();

You can review the full reference code here.

Previous
Register