Web3 – Calling Contract Functions with Parameters and Sending Ether from Geth

contract-deploymentcontract-developmentgo-ethereumweb3jweb3js

I have deployed a smart contract which basically splits the incoming funds to the specified addresses based on the entered ratio parameter.

Please find the code below:

pragma solidity ^0.4.23;

contract splitfund {

address admin;

constructor() public {

    admin = msg.sender;
}


function splitFunds(address[] withdrawaddress, uint[] proration) public payable {

    for(uint i = 0; i<withdrawaddress.length; i++) {
    withdrawaddress[i].transfer(proration[i] * msg.value/100);
    }
  }
}

Right now, i want to access the split funds function in the above contract by passing 1 ether from an address and splitting it in a 60:40 ratio and send it to addresses 0x2e46E9A4542B28B39C21Ed859486147969CB949F and 0x16292759f5e37144E37effe9Ef41998B1DfC5Df0 respectively. I was able to achieve this from Remix in Ropsten test network (https://ropsten.etherscan.io/tx/0xf88696620eeb60cb64df6cedff2585ce65e5b6a3b0e896813394d920d0a133c5#internal)

enter image description here

Can someone please let me know on how to execute the same using Geth/Web3JS/Web3J?!

Best Answer

This has been here before

Using truffle abstracting the ugly* stuff away from you: Web3 - how to send transaction with some data and include Ether at the same time?

Using web3 you would need to use this method and get the "input"* value (encoding the method signature and data that will be called, have a look at the "input" 0x969... from your screenshot) for your data field that should be set. Either copy it from remix (simplest way as you already have it) or calculate it yourself: https://github.com/ethereum/wiki/wiki/JavaScript-API#web3ethsendtransaction

Related Topic