Search code examples
ethereumsoliditytruffle

Truffle console variable declaration


I'm currently following this tutorial (https://medium.com/zeppelin-blog/the-hitchhikers-guide-to-smart-contracts-in-ethereum-848f08001f05) as I try to get into ethereum programming. Step 3 is interacting with the deployed contract.

When I enter

truffle(default)> var poe = ProofOfExistence1.deployed()

I get "undefined" as a result and cannot interact with the following commands as well. I definitely deployed the contract, because

truffle(development)> ProofOfExistence1.deployed()

gets me output and lists me all functions inside the contract etc. tried it with testrpc and geth testnet so I guess it's got something to do with truffle?


Solution

  • The .deployed() method returns a Promise. Try:

    truffle(development)> ProofOfExistence1.deployed().then(function(a) { poe = a; })
    ...
    truffle(development)> poe.address