#
Using RecurrentTransfer
The RecurrentTransferOperation
allows for initiating, modifying, and removing recurrent transfers on the Hive blockchain.
#
Creating a new Recurrent Transfer
Test it yourself: src/typescript/transaction/operations/recurrent-transfer/creating-recurrent-transfer.ts
import { createHiveChain, DefineRecurrentTransferOperation } from '@hiveio/wax';
// Initialize hive chain interface
const chain = await createHiveChain();
// Initialize a transaction object
const tx = await chain.createTransaction();
const from = "sender-account";
const to = "recipient-account";
const amount = chain.hiveCoins(100); // 100.000 HIVE
const memo = "Monthly subscription";
const recurrence = 24; // every day
const executions = 30; // for 30 days
tx.pushOperation(new DefineRecurrentTransferOperation({
from,
to,
amount,
memo,
recurrence,
executions
}));
// Get a transaction object holding all operations and transaction TAPOS & expiration data, but transaction is **not signed yet**
console.log(tx.transaction);
#
Generate Removal Using RecurrentTransferOperation
Generate removal removes recurrent transfer:
import { createHiveChain, RecurrentTransferRemovalOperation } from '@hiveio/wax';
// Initialize hive chain interface
const chain = await createHiveChain();
// Initialize a transaction object
const tx = await chain.createTransaction();
const from = "sender-account";
const to = "recipient-account";
const pairId = 12345;
// Use dedicated wax complex operation to generate recurrent transfer removal
// (recurrent_transfer_operation is generated under the hood having specified amount = 0)
tx.pushOperation(new RecurrentTransferRemovalOperation({
// If the amount is NOT specified, the removal operation will be automatically generated
from,
to,
pairId
}));
// Get a transaction object holding all operations and transaction TAPOS & expiration data, but transaction is **not signed yet**
console.log(tx.transaction);
#
Add Pair Id
In this example we add pair id to recurrent transfer, using RecurrentTransferOperation
(simply specify the pairId
field in the configuration):
Test it yourself: src/typescript/transaction/operations/recurrent-transfer/add-pair-id.ts
import { createHiveChain, DefineRecurrentTransferOperation } from '@hiveio/wax';
// Initialize hive chain interface
const chain = await createHiveChain();
// Initialize a transaction object
const tx = await chain.createTransaction();
const from = "sender-account";
const to = "recipient-account";
const pairId = 12345;
const amount = chain.hiveCoins(100); // 100.000 HIVE
const memo = "Monthly subscription";
// Use this time just for example default values for recurrence and executions which is 24 for recurrence and 2 for executions.
tx.pushOperation(new DefineRecurrentTransferOperation({
from,
to,
// Add pairId to the operation constructor
pairId,
amount,
memo
}));
// Get a transaction object holding all operations and transaction TAPOS & expiration data, but transaction is **not signed yet**
console.log(tx.transaction);