embark: Unable to access web3.eth.accounts in config/contracts.js

What I’m trying to do:

I originally wrote all my tests in the Truffle testing environment. However, after finding Ganache and Truffle were often crashing, I have turned to trying to write tests in Embark.

In order to deploy one of my contracts, I have to send two addresses into the constructor. I have started a local testrpc using embark simulator, which started ganache-cli with a mnemonic and 10 test accounts. I want to send the first and third argument into the constructor similar to the below:

initializeContract(web3.eth.accounts[0], web3.eth.accounts[2]);

What is actually happening:

Embark doesn’t seem to recognize web3. The error code is:

Error: Attempted to deploy contract without specifying parameters

I tried to check the status of the web3 instantiation after starting embark run, and it seems uninitialized? Should accounts and addresses be initialized?

image

Is there something I’m doing wrong to use and/or initialize web3?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 26

Most upvoted comments

Contract names might not be exactly the same. Just change them in the config and in the require.

Yes, it works!! Thank you so much @jrainville @iurimatias for your help to get this working! (edited: oops)

embark test can be used standalone. It boots a simulator for you and deploys the contracts that you choose. It’s an easy way to deploy only what you want with specific arguments to test them.

embark run is a way to run your Dapp. So it will deploy all your contracts, that’s where config/contracts.js comes in. You configure your contracts there and put your arguments like so:

contracts: {
  MyContract: {
    args: [ 'address1', 'address2']
  }
}

For more on contract configuration, check: https://embark.status.im/docs/configuration.html

embark run also processes your Javascript files and boots a webserver for you to test the Dapp.

You can test all of this with our demo easily by runnning embark demo, then cd embark_demo (might need an npm install on some OS) and embark run (it will boot a blockchain node for you and compile everything). Afterwards, you can go to localhost:8000 and play with the demo. It’s as simple as that. You can then tinker with the code, the contracts, the configs and it will recompile on change. The demo also comes with a test that you can run with embark test