dag_allowSpend

Grants permission for another wallet or metagraph to spend up to a specified amount from the user’s wallet in a metagraph token or DAG.

Parameters

Name
Type
Description

Data

Object<AllowSpend>

The allow spend object.

AllowSpend

type AllowSpend = {

  source: string;             // Wallet address signing the transaction

  destination: string;        // The destination address
                              // Must be a metagraph address

  amount: number;             // The amount to allow spend
                              // Must be in DATUM

  approvers: string[];        // An array with a single DAG address that can atomically approve this operation
                              // Can be a metagraph or wallet address

  currencyId: string | null;  // The currency metagraph identifier
                              // For DAG, this field must be null

  fee?: number;               // The fee in the currency of the currency metagraph, or DAG.
                              // If not provided, the default fee will be 0
                              // Must be in DATUM

  validUntilEpoch?: number;   // The global snapshot epoch progress for which this is valid until 
                              // If not provided, the default value will be currentEpoch + 30
                              // Minumum allowed value: currentEpoch + 5
                              // Maximum allowed value: currentEpoch + 60

};

The currentEpoch value can be pulled from the latest global snapshot. You can use dag4.js to easily get it:

const latestSnapshot = await dag4.network.l0Api.getLatestSnapshot();
const currentEpoch = latestSnapshot.value.epochProgress;

Return Type

String<Hash> - The hash of the allow spend transaction.

Example

await provider.request({
  method: "dag_allowSpend",
  params: [ 
    { 
        source: 'DAG5sz69nNwGF8ypn1yukFpg2pVJpdx5mnf1PJVc',
        destination: 'DAG3miCyHnvuoyywvnvnMzt35Y9Gs7EqTHQx6xtg',
        amount: 100000000,
        approvers: ['DAG3miCyHnvuoyywvnvnMzt35Y9Gs7EqTHQx6xtg'],
        currencyId: 'DAG8RdiwFhZcLmjrsz79jiKfstQmPaSqABphCK1P',
        fee: 0,
        validUntilEpoch: 1022060,
    }
  ]
});
// "2d9fe9bad17debed7c903f22b74aac8af270daea7995dd099a58d6b201547169"

Last updated

Was this helpful?