6
votes

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?

4

4 Answers

4
votes

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

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

To interact with the deployed contracts, you have to type in truffle console:

truffle<development)> ProofOfExistence1.at("copy its address after the migration").function name();
0
votes

I prefer to use truffle(development)> poe = ProofOfExistence1.at(ProofOfExistence1.address).

No need to worry about promises with this approach, easy to copy and paste test cases into the console .

0
votes

probably arriving too late, but my answer I hope it can be of help to someone else (as this great framework has helped me many times). This is the way I do it on my contract interactions:

let contract = await ProofOfExistence1.deployed()

contract.address

you could also interact by executing some function inside of your contract like this:

let function1 = contract.function1()

function1

Not an expert in blockchain, just a starter so sorry if this is not the best answer ;)