6

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?

Daniel Gretzke
  • 426
  • 4
  • 19

4 Answers4

4

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

truffle(development)> ProofOfExistence1.deployed().then(function(a) { poe = a; })
...
truffle(development)> poe.address
acdcjunior
  • 132,397
  • 37
  • 331
  • 304
  • 2
    A lot of tutorials around the web are still showing how to get the instance for the truffle version 2. This was updated with version 3. For the MetaCoin example, you can use: var meta;MetaCoin.deployed().then(a => { meta = a; }) – pzagor2 Jun 29 '17 at 08:28
1

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();
sheemar
  • 467
  • 3
  • 13
0

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 .

0TTT0
  • 1,288
  • 1
  • 13
  • 23
0

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 ;)

Luisca
  • 1
  • 1