0

I am very new to dApp-Development and therefore frankly i need some basic help. How can i get the address of my deployed contract by truffle in meteor? I hope there is a simple solution.

bumped to the homepage by Community 6 hours ago

This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

0

Truffle writes the address it deploys to during deployment when you run it, but afterwards it also stores the information about the deployed contracts under a directory called build/contracts. Each contract gets its own .json file, so if your contract is called MyContract you should have a file called MyContract.json.

The address of the contract will be towards the end of the file, in a field called address. Note that if you have deployed to multiple networks, you may have an address entry for each one, so you need to look through the file and make sure you have the right network. (It groups the entries by Network ID.)

To interact with the contract it's not enough to have the address. You will also need the ABI, which is the definition of the functions that your contract exposes. This is also found in the .json file generated by Truffle. You could pull this out and read it directly with web3.js, but it's easier to use the truffle-contracts library. That way you don't need to worry about finding the address either: just point Truffle's library to the JSON file and let it work out how to load the contract.

See this question for an example of reading the contract json file and interacting with it using truffle-contracts: Export a JS package from Truffle?

  • Thany you very much, can you maybe give me a hint, how to get truffle-contract into meteor? 'const contract = require('truffle-contracts');' doesn't seem to work – TimRicta Sep 28 '17 at 9:49
  • You should be able to pull it into your project with npm install truffle-contract – Edmund Edgar Sep 28 '17 at 11:03
  • do i have to move the truffle folder into the meteor project folder to get this work? – TimRicta Sep 28 '17 at 11:08
  • Also meteor throws this exeption: C:\Users\timri\AppData\Local\.meteor\packages\meteor-tool\1.5.2\mt-os.windows.x86_32\dev_bundle\server-lib\node_modules\fibers\future.js:280 throw(ex); ^ ReferenceError: artifacts is not defined at meteorInstall.ProductionContract.migrations.1_initial_migration.js (ProductionContract/migrations/1_initial_migration.js:1:18) at fileEvaluate (packages\modules-runtime.js:333:9) at require (packages\modules-runtime.js:228:16) .... – TimRicta Sep 28 '17 at 11:12
  • I'm not sure if there's a problem loading the truffle-contract library or whether it's Meteor seeing your truffle files and choking on them. Do you only get that error when the truffle directory is under your Meteor directory? If so it sounds like you need to somehow tell your Meteor build sytem not to try to read those files directly. – Edmund Edgar Sep 29 '17 at 0:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.