I'm having a problem with a smart contract I have deployed on a local testrpc network. I'm using truffle, nodejs and web3js.
I am running that testrpc network on Ubuntu 16.04, and into it there's is a simple contract deployed, which I had succesfully tested on another similar machine.
So, what I'm trying to do is sending Ether from one account to another via a simple script (which will be called from inside an empty html page that receives the following parameters: contract address, destination address and Ether amount).
The script gets those parameters from the browser and then calls the method "sendEther", which should in fact send the Ether... but it doesn't. Funny thing is that it doesn't raise an error, either.
The smart contract looks like this:
pragma solidity ^0.4.4;
contract Transfer {
address owner;
function Transfer () {
owner = msg.sender;
}
function sendEther (address dst) payable {
if(msg.value<=0) revert();
dst.transfer(msg.value);
}
}
This is the part of the script that should do the sending (every input parameter is correct):
try
{
var source = "0x8691202f56859bd5362f1033fa64e71cb4eae579";
var abi = [{"constant":false,"inputs":[{"name":"dst","type":"address"}],"name":"sendEther","outputs":[],"payable":true,"type":"function"},{"inputs":[],"payable":false,"type":"constructor"}];
var contract_addr = getParameterByName("contract");
var amount = getParameterByName("amount");
var destination = getParameterByName("destination");
var contract = new web3.eth.Contract(abi, contract_addr, {from: source, to: destination, value: parseInt(amount)});
var hash = contract.methods.sendEther(destination);
...lots of "document.write"...
} catch (e) {
...error handling...
}
The output I get indicates that there's been no error, but when I go to a truffle console on the machine that hosts the script, it does not reflect the changes of balance on the involved accounts (source and destination).
This is the output (the results of all the "document.write"):
ABI: [{"constant":false,"inputs":[{"name":"dst","type":"address"}],"name":"sendEther","outputs":[],"payable":true,"type":"function","signature":"0x48c981e2"},{"inputs":[],"payable":false,"type":"constructor"}]
Contract: {"currentProvider":{"host":"http://localhost:8545","timeout":0,"connected":false},"_requestManager":{"provider":{"host":"http://localhost:8545","timeout":0,"connected":false},"providers":{},"subscriptions":{}},"givenProvider":null,"providers":{},"_provider":{"host":"http://localhost:8545","timeout":0,"connected":false},"_ethereumCall":{},"options":{"from":"0x8691202F56859BD5362f1033FA64E71cb4EaE579","to":"0x09b74dc58118140deec480d562651e42ae3b21ad","value":1000000000000,"address":"0x377D5848c8A7B68D20CcE114f23AD959a62CC9f7","jsonInterface":[{"constant":false,"inputs":[{"name":"dst","type":"address"}],"name":"sendEther","outputs":[],"payable":true,"type":"function","signature":"0x48c981e2"},{"inputs":[],"payable":false,"type":"constructor"}]},"defaultAccount":null,"defaultBlock":"latest","methods":{},"events":{},"_address":"0x377D5848c8A7B68D20CcE114f23AD959a62CC9f7","_jsonInterface":[{"constant":false,"inputs":[{"name":"dst","type":"address"}],"name":"sendEther","outputs":[],"payable":true,"type":"function","signature":"0x48c981e2"},{"inputs":[],"payable":false,"type":"constructor"}]}
Contract address: 0x377d5848c8a7b68d20cce114f23ad959a62cc9f7
Amount (weis): 1000000000000
Transaction hash: {"arguments":["0x09b74dc58118140deec480d562651e42ae3b21ad"],"_method":{"constant":false,"inputs":[{"name":"dst","type":"address"}],"name":"sendEther","outputs":[],"payable":true,"type":"function","signature":"0x48c981e2"},"_parent":{"currentProvider":{"host":"http://localhost:8545","timeout":0,"connected":false},"_requestManager":{"provider":{"host":"http://localhost:8545","timeout":0,"connected":false},"providers":{},"subscriptions":{}},"givenProvider":null,"providers":{},"_provider":{"host":"http://localhost:8545","timeout":0,"connected":false},"_ethereumCall":{},"options":{"from":"0x8691202F56859BD5362f1033FA64E71cb4EaE579","to":"0x09b74dc58118140deec480d562651e42ae3b21ad","value":1000000000000,"address":"0x377D5848c8A7B68D20CcE114f23AD959a62CC9f7","jsonInterface":[{"constant":false,"inputs":[{"name":"dst","type":"address"}],"name":"sendEther","outputs":[],"payable":true,"type":"function","signature":"0x48c981e2"},{"inputs":[],"payable":false,"type":"constructor"}]},"defaultAccount":null,"defaultBlock":"latest","methods":{},"events":{},"_address":"0x377D5848c8A7B68D20CcE114f23AD959a62CC9f7","_jsonInterface":[{"constant":false,"inputs":[{"name":"dst","type":"address"}],"name":"sendEther","outputs":[],"payable":true,"type":"function","signature":"0x48c981e2"},{"inputs":[],"payable":false,"type":"constructor"}]}}
Transaction details: {"isFulfilled":false,"isRejected":false}
Can you tell me what's not working here, please? I'm pretty lost right now...
Please ask me for any additional information if necessary.
Thanks in advance! :)