Using web3
0.20.3
I want to call function and send some Etherium at the same time.
JavaScript
Contract = web3.eth.contract(ABI);
Instance = Contract.at('0x162b74ea16da6ae9d7f7b349eaeab2fcadf4e835');
Instance.setData("name", "url", function(err, result) {
console.log(err, result);
});
Solidity
function setData(string name, string imageUrl) public payable {
accounts[msg.sender].name = name;
accounts[msg.sender].imageUrl = imageUrl;
accounts[msg.sender].bid = accounts[msg.sender].bid + msg.value;
emit Bid(msg.sender, accounts[msg.sender].bid);
}
function() public payable { // fallback function
accounts[msg.sender].bid = accounts[msg.sender].bid + msg.value;
emit Bid(msg.sender, accounts[msg.sender].bid);
}
- I know how to send Ether: https://github.com/ethereum/go-ethereum/wiki/Sending-ether
- I know how to call function.
- How do I call function and send Ether at the same time using simple syntax?
Ideally something like that:
Instance.setData("url", "name", {value: "1000000000000000000"}, function(err, result) {
console.log(err, result);
});
(note adding extra value
parameter)
from: web3.eth.accounts[0]
to the object you put thevalue
in to make sure web3 will try to send from the 'current' account.myContractInstance.myStateChangingMethod('someParam1', 23, {value: 200, gas: 2000});
Can I have my time back? How do we mark the question as pointless, resolved, it was always working, maybe I was so tired and forgot to save the file or reload the page...