Bulk Transfer

Overview

Batch transaction

Bulk transfer leverages pallet-utility runtime module from substrate to send multiple transfer extrinsics to runtime.

Here is the example code provided by Polkadot.js cookbook:

// construct a list of transactions we want to batch
const txs = [
  api.tx.balances.transfer(addrBob, 12345),
  api.tx.balances.transfer(addrEve, 12345),
  api.tx.staking.unbond(12345)
];

// construct the batch and send the transactions
api.tx.utility
  .batch(txs)
  .signAndSend(sender, ({ status }) => {
    if (status.isInBlock) {
      console.log(`included in ${status.asInBlock}`);
    }
  });

Usage

To use bulk transfer in other systems using Parallel, Developers must installParallel.js, aJavascript frontend library to interact with Parallel parachain.

bulkTransfer

ParameterTypeDescription

api

APIPromise

Initialized Parallel API

sender

Keyring

Account to send funds from

recipients

Array<string>

Array of recipient addresses in string

amounts

Array<string>

Array of amount to transfer to

Example Code

import { ApiPromise, WsProvider } from '@parallel-finance/api';
import { Keyring } from "@polkadot/keyring";
import { bulkTransfer } from "@parallel-finance/bulk-transfer";

async function usage() {
  // Initialize API
  const provider = new WsProvider('wss://heiko-rpc.parallel.fi');
  const api = await ApiPromise.create(
    options({
      types: {
        TAssetBalance: 'Balance'
      },
      provider
    })
  );
  // Initialize an account
  const keyring = new Keyring();
  const mnemonic = "test test test test test test test test test test test test"
  const sender = keyring.addFromUri(mnemonic, { name: 'bulk transfer test' }, 'sr25519');
  // Recipients 
  const recipients = [
    'stAZnJwXAvRRo884Anfu2in9SBB6tssvcsjBAZnvnVn53krpP',
    'st8p7os56kbysAKCxRjC1PeUyobEP8b94sQkBbmeWSc2GJzEt'
  ];
  // Amounts
  const amounts = ['1000', '1000'];
  // Execute bulk transfer
  await bulkTransfer(api, sender, recipients, amounts);
}

await usage();

Glossary

substrate: A blockchain development framework developed and maintained by Parity Technologies.

pallet-utility: Utility pallet for substrate runtime, it includes generic helper functions for blockchain runtime processing

extrinsic: Extendable transaction. Coined by Polkadot, Unlike regular transaction in blockchain where it sends bytecode for smart contracts, extrinsic has specific data structure optimized for each blockchain.

APIPromise: The data type where it refers initialized asynchronous api for interacting with blockchain. It is used for making extrinsic

Keyring: The data type where it refers to initialized account to be used with initialized api.

Last updated