I've found what i was doing wrong in my deploy process and why accessing the contract after creation with possible but would throw the error with the address.
Turns out this is not the contract ABI :
var currencyContract = web3.eth.contract([{"constant":false,"inputs":[{"name":"_addr","type":"address"}],"name":"disapprove","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"_target","type":"address"},{"name":"_proxy","type":"address"}],"name":"isApprovedOnceFor","outputs":[{"name":"_r","type":"uint256"}],"type":"function"},{"constant":false,"inputs":[{"name":"_proxy","type":"address"}],"name":"isApproved","outputs":[{"name":"_r","type":"bool"}],"type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_value","type":"uint256"},{"name":"_to","type":"address"}],"name":"sendCoinFrom","outputs":[{"name":"_success","type":"bool"}],"type":"function"},{"constant":false,"inputs":[{"name":"_addr","type":"address"},{"name":"_maxValue","type":"uint256"}],"name":"approveOnce","outputs":[],"type":"function"},{"constant":true,"inputs":[{"name":"_addr","type":"address"}],"name":"coinBalanceOf","outputs":[{"name":"_r","type":"uint256"}],"type":"function"},{"constant":false,"inputs":[{"name":"_value","type":"uint256"},{"name":"_to","type":"address"}],"name":"sendCoin","outputs":[{"name":"_success","type":"bool"}],"type":"function"},{"constant":true,"inputs":[],"name":"coinBalance","outputs":[{"name":"_r","type":"uint256"}],"type":"function"},{"constant":false,"inputs":[{"name":"_addr","type":"address"}],"name":"approve","outputs":[],"type":"function"},{"inputs":[],"type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":false,"name":"value","type":"uint256"},{"indexed":true,"name":"to","type":"address"}],"name":"CoinSent","type":"event"}]);
So the fix the issue i had to do :
var MyContract = web3.eth.contract(currencyContract.abi);
MyContract.at("0xADDRESS")
A little too much to wade through and fully sort out for you, but here is the general idea.
if(p.recipient.call.value(p.amount*1000000000000000000)(transactionBytecode)) {
// do something
} else {
// do something else
}
The error is saying that there is an expected return value and your code seems to be (is) ignoring it.
Basically, it's warning you about a possible oversight in the contract.
// do something
, and // do something else
are obviously placeholders. A word of caution: It's important to structure things so they do what you want and provide re-entrance protection. A general pattern for this is:
- Optimistic accounting. Ensure a completely resolved contract state.
- Try the send/untrusted function & check the result.
- Revert Optimistic account (possibly with throw) if necessary. Log events.
So, you can do (pseudo):
balance[x] += amount;
if(!user.send(amount)) throw;
LogSent(user, amount);
Optimistic accounting first means balance[x] is already adjusted in the case the called contract loops around and calls another function in this contract.
As well as resolving the immediate issue the compiler is warning about, restructure it so there are no state changes after:
if(p.recipient.call.value(p.amount*1000000000000000000)(transactionBytecode))
Hope it helps.
Best Answer
you could use a modifier :
or you could just use simple checking (throw if send failed for some reason):