Batch Transfers on Dune Network

Fabrice Le Fessant
Dune Network
Published in
3 min readSep 19, 2019

Now that Dune Network is running publicly, we have started focusing on the next big features we want to add: the Love VM for smart-contracts, the Ironmin storage layer, some very useful tools, etc. Yet, we think that small features can also happen to be very useful, and, from time to time, we add one of them to Dune Network. For example, during the summer, we implemented the Batch Transfer command in the command line client,dune-client.

The idea is quite simple: sometimes, you want to transfer some tokens to several accounts. In Dune, because of the counter on operations, you can only send one operation per block, which means that you will have to wait for as many blocks as accounts you want to transfer to. With a batch transfer, you can send everything in one operation! During the airdrop, for example, we used that feature to send tokens to 250 accounts in the same operation. The only limitations are the maximal operation size, and the maximum gas per operation.

Here is an example:

$ dune-client dune batch transfer 40 from my-account to other-accounts.json

In this example, we transfer a total sum of 40 $duns from an account called my-account to some other accounts, specified in the file other-accounts.json. The command starts with dune, as most of the commands that we added, to avoid name clashes.

Let’s have a look at the file other-accounts.json:

[
{ "address": "dn1MkyeDTMR65EcQ9dEXST2jeeJ5AheHRdQW", "amount": "10000000" },
{ "address": "dn1WNZHRsKixA9bKuqVGxZB1v4eSZM5Z1ufH", "amount": "5000000" },
{ "address": "dn1Ucguc6y6CktF1n3JeQaWvkFGARgvfS6Pf", "amount": "10000000" },
{ "address": "dn1cnZtsxra4veEBmYdSbex2iwJV7Wob7V5c", "amount": "5000000" },
{ "address": "dn1d3rVhmXJ8oRyoUCCdiuYkR9EY4YCbRY3V", "amount": "10000000" }
]

It’s a simple list of records, each one containing an address” and an amount” (in μDUN).

The dune-client command will verify that the total sum is equal to the amount given as argument. Small trick, if you don’t want to compute it, just call the command with 0, it will print something like:

$ dune-client dune batch transfer 0 from my-account to other-accounts.json
Total doesn’t match:
Expected: 0
Got: 40

You can then issue the command with the correct total.

If you use a Ledger Nano, the Dune app will not be able to parse the operation, but it’s not a problem, the device will just print an “unrecognized operation” and ask you for validation before signing.

Of course, all this can also be done using direct RPCs to the node, but using dune-client, the gas and fees are automatically computed, which is especially useful if you are calling smart contracts! To call a smart contract, you just need to add an "arg” field to the associated transfer with the argument that you want to pass to the contract:

[
{ "address": "dn1MkyeDTMR65EcQ9dEXST2jeeJ5AheHRdQW", "amount": "10000000" , "arg" : "Pair 1 2" },
{ "address": "dn1WNZHRsKixA9bKuqVGxZB1v4eSZM5Z1ufH", "amount": "5000000" , "arg": "\"a string argument\"" },
{ "address": "dn1Ucguc6y6CktF1n3JeQaWvkFGARgvfS6Pf", "amount": "10000000" },
]

We hope this new command will be useful for you. During the airdrop, we used it 94 times to transfer tokens to 23,512 accounts, in less than 2 hours!

--

--

Fabrice Le Fessant
Dune Network

Former researcher at INRIA, Fabrice founded OCamlPro, now CEO at Origin Labs and active dev of the Dune Network blockchain platform.