When calling from Remix IDE, it executes successfully. But when calling from web3 v1.2.9, it gives the above error.
Here is the contract : https://ropsten.etherscan.io/address/0x8ec0ca8b2fb402ff86cee42ade5e9072a6156b63#code
sol code:
/**
*Submitted for verification at Etherscan.io on 2020-07-16
*/
pragma solidity 0.5.1;
contract SendEther {
event Transferred(uint256 value , address sender);
function() external payable{}
function SendEtherToAddresses(address payable[] memory _addresses, uint256[] memory _amounts) public payable {
for (uint256 i=0; i < _amounts.length; i++) {
_addresses[i].transfer(_amounts[i]);
}
emit Transferred(msg.value, msg.sender);
}
}
js code:
window.web3 = new Web3(ethereum);
ethereum.enable();
eth_Contract = new web3.eth.Contract(abi, contractAddress);
var addresses = '0xB0Dc12Ef30D707A52a079d915435Ee0B5C03e8CC';
var amounts = '0.0005'
const address = web3.utils.toChecksumAddress(ethAddress); // metamask address
Eth_Add_Arr = addresses.split(",");
Eth_Amt_Arr = amounts.split(",");
var Eth_Amt_Arr_1=new Array();
TotalAmount = 0;
for (var i = 0; i < Eth_Amt_Arr.length; i++) {
var x = parseInt(web3.utils.toWei(Eth_Amt_Arr[i], "ether"));
Eth_Amt_Arr_1[i] = x.toString();
TotalAmount += x;
};
eth_Contract.methods.SendEtherToAddresses(Eth_Add_Arr, Eth_Amt_Arr_1).send({
from: address,
to: contractAddress,
value: TotalAmount,
gasPrice: web3.utils.toWei("1", "Gwei"),
gas: 40000
},
(error, transactionHash) => {
if (!error) {
console.log(transactionHash);
SaveRegistration(address, sponsorId, transactionHash);
}
else {
swal(e);
}
})
Please help!