0

I want to send different values of ethers to multiple different addresses in one single transaction and for that I've created a smart contract, but I'm not getting how would I'll call the contract function by web3 py Here's my contract code

pragma solidity ^0.4.21;

contract PayMultiple {
    using SafeMath for uint;

    function pay(address[] payees, uint[] values) public payable{
         //Make sure both arrays have matching lengths
         require(payees.length == values.length);

         //Make sure total of the values is the amount sent
        uint total = 0;
        for(uint i = 0; i < payees.length; i++){
            total = total.add(values[i]);
        }
        require(total == msg.value);

        //Actually send to the payees
        for(i = 0; i < payees.length; i++){
            payees[i].transfer(values[i]);
        }
    }
}

1 Answer 1

0

I fixed your script abit.

//SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

contract PayMultiple {

function pay(address[] memory payees, uint[] memory values) public payable{
     require(payees.length == values.length);

    uint total = 0;
    for(uint i = 0; i < payees.length; i++){
        total += values[i];
    }
    require(total == msg.value);

    for(uint i = 0; i < payees.length; i++){
        (bool success,) = payable(payees[i]).call{value:values[i]}("");
        require(success,"Not successfull");
    }
}

}

Try sending some WEI, for example:

Random addresses: ["0xdD870fA1b7C4700F2BD7f44238821C26f7392148","0x583031D1113aD414F02576BD6afaBfb302140225","0x4B0897b0513fdC7C541B6d9D7E929C4e5364D2dB"]

Random values:

[3,3,4]

Make sure that you send 10 WEI.
If you send ETHER, than random values should be:

[300000000000000000,300000000000000000,400000000000000000]
1
  • Thank you for correction but I want the web3 py script by which I can interact with this contract Commented Jul 27, 2022 at 5:34

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.