0

i want to make multiple transfer
this is my code

function transferMulti(address[] _to, uint[] _value) public returns(bool success) {
    require(_to.length == _value.length, "require _to[] size == _value[] size");

    for(uint8 i=0; i<_to.length; i++) {
      transfer(_to[i], _value[i]);
    }

    return true;
}

but Actually, it was like Mint, Not Transfer...
how to maintain msg.sender?

1

In standard ERC20 contracts the transfer() function can only be called by the account that owns the tokens. If you want to put a contract in the middle, the caller (msg.sender) of the transfer() function will become the contract, rather than the account that owns the tokens.

If the tokens are owned by an external account not a contract, they will have to either first transfer the tokens to the contract or call approve() to give the contract permission to move them with transferFrom().

1

You need to declare your transfer function (by transfer I mean transfer, not transferMulti) as public rather than as external.

When public function is called from within contract where it is declared, msg.sender is preserved, but for external functions it is overridden. See documentation for more details.

BTW, I see two major issues in your code: 1. you use uint8 for counter, thus you will get infinite loop in case _to.lengeth >= 256, and 2. You ignore value returned by transfer method.

  • thank you. i change code – JungTa Apr 30 at 4:03
0

I found a way
it use delegatecall
The important point is that you only need to write the data type of the parameter.

function transfer(address _to, uint256 _value) public returns (bool success) {
    ...
}

function transferMulti(address[] _to, uint256[] _value) public returns (bool success) {

    require(_to.length == _value.length, "_to.length == _value.length");

    for(uint i=0; i<_to.length; i++) {
        address(this).delegatecall(abi.encodeWithSignature("transfer(address,uint256)", _to[i], _value[i]));
    }

    return true;
}

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