If i have a list of addresses and the exact amount of tokens that I want sent to each address, how can I hardcode a transfer function to transfer the exact amount of tokens to all specific addresses if called?

1 Answer 1


In my opinion, the best way is to make a function that takes an array of addresses as a parameter:

Solidity function:

function foo(address[] add, int value) public {

    for (int i = 0; i <= add.length; i++){

If you are working with web3 (for example), you can just pass a javascript array with all your addresses as strings inside.

If the amount is specific for all addresses:

  function foo(address[] add, int[] values) public {

        for (int i = 0; i <= add.length; i++){

Be sure that the indexes match correctly.

Update to answer the comments:

If you want to retrieve addresses and balances of tokens from old contract, you can do it ONLY if you have implemented the functionnality to get all addresses and their balances in the old contract, something like:


address[] listOfAddresses;
int[] balancesOfAddresses;

    function getAddresses() public returns (address[], int[]){

        return (listOfAddresses, balanceOfAddresses);

Or any other way to get this information.


address[] listOfAddresses;
int[] balanceOfAddresses;
function(address[] addresses, int[] balances) public {

Using this, you could get the information from one contract and push them to an other.

Remark: You could use mapping as well, but I'm not very familiar with them. Remark: If you first contract do not have the capability to retrieve the data, I'm afraid you are stuck. Or maybe if you go through the chain, you could retrieve transactions, but I cannot help on that.

  • Is it possible to snapshot the 'balances' mapping from an old contract ? and give them free new tokens based on the amount in the mapping
    – NowsyMe
    Commented Nov 12, 2017 at 7:37
  • My first thougth would be, if you have a function that returns all the balances, to call it and use the result to send new free tokens via your new contract. Commented Nov 12, 2017 at 7:40
  • but then it would be the same amount of tokens to all right
    – NowsyMe
    Commented Nov 12, 2017 at 8:59
  • Not if your function from old contract sends you 2 arrays: One with addresses, an other with balances, and the indexes would match. If you do have that, you can just loop trhough to send tokens to addresses one by one. Commented Nov 12, 2017 at 9:02
  • Thanks for answering! so I would have to, have those implemented in the old contract to be able do this right, like a look up table array
    – NowsyMe
    Commented Nov 12, 2017 at 10:45

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.