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")
Try this:
let EVENT = [
{name: "PositionKey", size: 256, indexed: true },
{name: "Opener" , size: 160, indexed: true },
{name: "EtherTossed", size: 256, indexed: false},
{name: "OddEven" , size: 8, indexed: false},
];
function decode(data) {
let event = {};
let index = "0x".length;
for (let i = 0; i < EVENT.length; i++) {
if (!EVENT[i].indexed) {
let name = EVENT[i].name;
let size = Math.floor(EVENT[i].size / 4);
event[name] = web3.toBigNumber("0x" + data.substr(index, size));
index += size;
}
}
return event;
}
Best Answer
Once you have a BN object, you can use
.toString()
or.toNumber()
on it.Per the comments below, your function isn't actually receiving a
BN
. It's getting some sort ofResults
object that has a single key in it: 0. (Presumably if the function returned multiple values, there would be more keys.)So first extract the
BN
from theResult
: