trufflesuite / ganache-cli-archive

Fast Ethereum RPC client for testing and development. See https://github.com/trufflesuite/ganache for current development.
https://www.trufflesuite.com/ganache
MIT License
3.36k stars 695 forks source link

How can I determine right ganache instance? #799

Closed sfl0r3nz05 closed 3 years ago

sfl0r3nz05 commented 3 years ago

Hi, I have deployed a ganache-cli on docker. In addtion, I have deployed the smart contract successfully through truffle migrate, however when I try to access from the application a new instance is generated even though I define correctly the mnemonic and the network id.

Expected Behavior

The expected behavior is that when emitting a transaction, the number of blocks increases, for example to 5. image

Current Behavior

In the following images you can see how when the application is launched (via postman) a transaction is executed, but generating the block Number 1, while ganache once the contract is deployed is in block 4.

Node App behavior: image

Ganache behavior: image

I have passed both: mnemonic and network id (determined when contract was deployed) const provider = ganache.provider({mnemonic: process.env.GANACHE_CLI, network_id: process.env.NETWORK_ID});

I have also passed smart contract address: const contract_address = process.env.CONTRACT_TRUST_ANCHOR;

image image

Docker environment is set to true in docker-compose image

Network definition in truffle-config.js image

Possible Solution

I think it might be a matter of missing some of the options defined for ganache-cli

Your Environment

davidmurdoch commented 3 years ago

Hey, so the following code creates a javascript client only (without the webserver). Perhaps that's the issue?

const provider = ganache.provider({mnemonic: process.env.GANACHE_CLI, network_id: process.env.NETWORK_ID});

If you want to launch via docker you'll need to pass ganache-cli options through the docker container. See: https://github.com/trufflesuite/ganache-cli#docker

sfl0r3nz05 commented 3 years ago

Hey @davidmurdoch,

To deploy successfully ganache on docker-compose, I recommend this configuration: image

To interact with ganache, i recommend to use websocket to recover events:

const Web3 = require("web3"); const web3 = new Web3(ws://${process.env.HOST_PROVIDER_GANACHE}:${process.env.PORT_PROVIDER_GANACHE});

Also it works with http, however, this configuration it is not able to decode events.