# Batch Transfer

Below contract defines a batch transfer which accepts a list of addresses and amounts and then transfers specified amount to specified address in the list

Copy // Declare the contract is written in soliditypp 0.4.3. Backwards compatibility is guaranteed for generating the same compiling result. pragma soliditypp ^0.4.3; // Define contract BatchTransfer contract BatchTransfer { // Define a message listener. Every external method should be defined as message listener in Solidity++ // Define listener name and parameters. Visibility is not necessary. Message listener has no return value // Messsage listener "transfer" is defined with a passed-in parameter of a uint array, in format of address in odd element and amount in even onMessage transfer(address[] calldata addrs, uint[] calldata values) payable { // Check if the parameter length is even because each address should have corresponding amount require(addrs.length == values.length); uint256 totalAmount = 0; for(uint i = 0; i < addrs.length; i++) { address addr = addrs[i]; uint amount = values[i]; totalAmount = totalAmount + amount; require(totalAmount >= amount); if(amount > 0) { // Transfer to address addr.transfer(msg.tokenid, amount); } } require(totalAmount == msg.amount); } }

# Key features

  • address[] calldata addrs This shows how data can be passed to a contract in the form of an array and parsed.

  • uint256 totalAmount = 0; This variable is local, and is not stored on the blockchain.

  • require statements. If the argument is false, the transaction will be reverted.

  • for, if statements, standard control flow.