I am trying to build a simple double escrow contract. I have an enum for the state:
enum State { Created, Locked, Inactive }
State public state;
When I try to interact with the contract through the truffle console, I can get the enum type to return:
but I don't understand how to make comparisons with the returned value. Can someone tell me how to compare the returned value?
Best Answer
It's a BigNumber: https://github.com/ethereum/wiki/wiki/JavaScript-API#a-note-on-big-numbers-in-web3js
Try this to get the idea:
Hope it helps.
Update ... this will be a little rough because it's a picture and not code I can play with. You're returning a promise with this part.
return instance.state()
. Now, you have to do something with that promise.var state =
is a mistake, because you don't want it to be a promise.I'm going to break it down a little bit for readability and illustration.
Try:
As a scripted thing, I would probably chain these so things don't thunder ahead too fast. Wait for the instance, then query the function.
See how the promises are starting to form a chain? You can keep returning promises, then close up the block and append
.then(...
to pass the results into the next step. In other words, if you need another interaction with the contract after myconsole.log()
, you wouldreturn
the function, and then carry on at});
with another.then()
.Just going by sound here, so I hope I didn't flub the syntax.
Hope it helps.