Skip to main content

vault.ensureTransferFeeAllowance(EnsureTransferFeeAllowance)

Ensure an ERC20 allowance is set to pay the vault transfer fee for a given token transfer. If the allowance is insufficient, it submits an approval transaction.

EnsureTransferFeeAllowance Type Parameters

ParameterTypeRequiredDescription
allowanceSignerSignerRequiredSigner that pays the transfer fee. Must be connected to a provider.
vaultstringRequiredVault address that computes the transfer fee.
tokenstringRequiredSecurity token address being transferred.
erc20stringRequiredERC20 token address used to pay the fee.
transferAmountHumanstringRequiredTransfer amount in human-readable units (e.g., "2").

Returns

FieldTypeDescription
statusalready_sufficient or approvedWhether an approval was sent.
vaultstringVault address.
feeTokenstringERC20 token address used for fees.
transfer{ token: string; amountHuman: string; amountUnits: bigint; tokenDecimals: number }Transfer amount details.
fee{ requiredAllowance: bigint; allowanceBefore: bigint; allowanceAfter: bigint }Fee allowance details.
approvedBystringAddress that submitted the approval (or current allowance owner).
receiptTransactionReceiptOnly present when status is 'approved'.

Usage

TypeScript

import 'dotenv/config';
import { RWA, Chain, type SDKInit } from "@peaq-network/rwa";
import { JsonRpcProvider, Wallet } from "ethers";

async function main() {
  // 0. Create RWA instance and get provider
  const provider = new JsonRpcProvider(process.env.HTTPS_BASE_URL);
  const init: SDKInit = { chainId: Chain.AGUNG, provider: provider };
  const rwa_sdk = new RWA(init);

  // 1. Allowance signer (pays transfer fee)
  const alice = new Wallet(process.env.ALICE_PRIVATE_KEY!, provider);

  // 2. Ensure transfer fee allowance
  const result = await rwa_sdk.vault.ensureTransferFeeAllowance({
    allowanceSigner: alice,
    vault: "0x907229D0A25A5Bb16F0ff3D890f38Eb4Ad52Ea1a",
    token: "0x2a6aA5ef4e236aeE4247EAA7B926cd843a95bFc8",
    erc20: rwa_sdk.getAddresses().erc20.peaq,
    transferAmountHuman: "2"
  });
  console.log("Result", result);
}

main().catch((err) => {
  console.error(err);
  process.exit(1);
});

JavaScript

import 'dotenv/config';
import { RWA, Chain } from "@peaq-network/rwa";
import { JsonRpcProvider, Wallet } from "ethers";

async function main() {
  // 0. Create RWA instance and get provider
  const provider = new JsonRpcProvider(process.env.HTTPS_BASE_URL);
  const rwa_sdk = new RWA({ chainId: Chain.AGUNG, provider });

  // 1. Allowance signer (pays transfer fee)
  const alice = new Wallet(process.env.ALICE_PRIVATE_KEY, provider);

  // 2. Ensure transfer fee allowance
  const result = await rwa_sdk.vault.ensureTransferFeeAllowance({
    allowanceSigner: alice,
    vault: "0x907229D0A25A5Bb16F0ff3D890f38Eb4Ad52Ea1a",
    token: "0x2a6aA5ef4e236aeE4247EAA7B926cd843a95bFc8",
    erc20: rwa_sdk.getAddresses().erc20.peaq,
    transferAmountHuman: "2"
  });
  console.log("Result", result);
}

main().catch((err) => {
  console.error(err);
  process.exit(1);
});

Example outputs

Result {
  status: 'approved',
  vault: '0x907229D0A25A5Bb16F0ff3D890f38Eb4Ad52Ea1a',
  feeToken: '0x...',
  transfer: {
    token: '0x2a6aA5ef4e236aeE4247EAA7B926cd843a95bFc8',
    amountHuman: '2',
    amountUnits: 2000000000000000000n,
    tokenDecimals: 18
  },
  fee: {
    requiredAllowance: 1000000000000000000n,
    allowanceBefore: 0n,
    allowanceAfter: 1000000000000000000n
  },
  approvedBy: '0x16cd4D21537eD8F33bE08271A9FA6DCC426709b2',
  receipt: ContractTransactionReceipt {
    ...
  }
}