2

I am trying to implement batch transactions alongside the normal balances.transfer. Because of several reasons (constructing transaction more than one stage and polkadot lib is not helping there) i am using @substrate/txwrapper-polkadot methods.balances.transfer and now i am trying methods.utility.batchAll. However i am facing something weird.

For transfer i used this:

    const unsigned = methods.balances.transfer(
      {
        dest: toAddress,
        value,
      },
      {
        address: account.address,
        blockHash,
        blockNumber,
        eraPeriod: 64,
        genesisHash,
        metadataRpc,
        nonce,
        specVersion,
        tip,
        transactionVersion,
      },
      {
        metadataRpc,
        registry,
      },
    );

This function takes 3 parameter: function transfer(args: BalancesTransferArgs, info: BaseTxInfo, options: OptionsWithMeta): UnsignedTransaction

This args: BalancesTransferArgs takes dest and value.

utility.batch however uses UtilityBatch as args :

    calls: ({
        callIndex?: string;
        args?: string;
    } | string)[];

I tried to use same args part (first part of the unsigned that i wrote up there) of batch transfer from another transaction which i get with api.rpc.chain.getBlock:

[{"callIndex":"0x0500","args":{"dest":{"id":"1w3QEceeCRN2Rv3GfUohY6yTpRUoo4BRdQ2b7s2jTgK4q4y"},"value":142062126800}}, {"callIndex":"0x0500","args":{"dest":{"id":"157xqEJLZDUmhc1RFvUDitKP3ygFDsJeXHifJw1Th2Pn7khH"},"value":130297371500}}, {"callIndex":"0x0500","args":{"dest":{"id":"13qkt6YBJyqzh4jdtJ4dooJDsTgAGKWoM2MwHreWN7LpYEHc"},"value":428418876800}}, {"callIndex":"0x0500","args":{"dest":{"id":"15sSvgpSsonimLWpHv7ZUhyNoXjd4VNMm2wpDeDVtcp2W58"},"value":999200000000}}, {"callIndex":"0x0500","args":{"dest":{"id":"13ee8dYeLBR7iaGEcSjbaC7ooRw2U5iSNexdFdTEo4VBVvVN"},"value":150723408800}}, {"callIndex":"0x0500","args":{"dest":{"id":"1555Ub7YF1tiyDv7JzUNToVjbUzAoK6X8k9RGGUYMK7ZUwAk"},"value":14200000000}}]

but its not accepting parameter as object like this because it wants it as string and i really couldn't figure what should i put there.

And what is callIndex? What it should be?

Can Anyone help? Thanks

1 Answer 1

5

I think it will be helpful for you to check the batchAll example in the txwrapper-core repository. It uses transferKeepAlive and batchAll but the concept is basically the same.

In this example you will notice that :

  1. First the const txMethods is defined where txInfo.method (the method from the UnsignedTransaction) is returned.
  2. Then in the calls argument of utility.batchAll this txMethods is passed.

This will work because the calls argument of batch or batchAll can be an array of UnsignedTransaction.method as mentioned in utility.batch and also in the comment above the utility.batchAll call in the example.

Regarding your question on what callIndex is, you can check the following:

  • This post from Shawn Tabrizi where he explains how calls are encoded.
  • Check some examples of call indices from the Balances pallet in Substrate :
  • Important to keep in mind that these indices can change between runtime upgrades (as mentioned also by Jaco here in more detail)
2
  • Thank you. Although I looked at the normal transfer from there, I completely forgot about the existence of the example part. Still missing staking tho.
    – Jozzy
    Commented Feb 23, 2023 at 17:05
  • What do you mean when you say "missing staking"? If it is not very closely related to this question maybe you would like to create another question ?
    – dominique
    Commented Feb 24, 2023 at 9:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.