Ganache with RSK
Note for For MAC OSX Developers
- Ensure you are running xcode directly and not the command-line instance. Run
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
Clone the RSK truffle-integration
- git clone https://github.com/rootstock/truffle-integration
- cd truffle-integration/
Open a terminal
cd /truffle-integration/docker # Where you've cloned the repo docker build --tag regtest -f Dockerfile.RegTest .
This comamnd will build download Rskj node and build the image. It takes about 10 mins for the first time downloading.
Once built, you can run an image container
docker run -d --name regtest-node-01 -p 4444:4444 -p 4445:4445 -p 30305:30305 regtest
This command will start an RSKJ node with port 4444, 4445 and 30305 open
To shut down or remove the active container
docker container list || docker kill <container id> || docker rm <container id>
Run docker commands with
RSKJ Docker Contribute
- Sign in at https://hub.docker.com/ (or register a new account)
- Navigate to
npm install. This will install required dependencies for ganache
npm startwill start Ganache in development environment
- Navigate to
truffle migrate --reset --network regtestto deploy Coin smart contract. run it twice to avoid truff issue #2224
- Once deployed, run
truffle console --network regtest. The Coin variable is already defined in the console.
- Mint Coin
- Then, send Coin by
- For the EIP20, check balance
- Transfer from the minter account to another account
- Approve another account for certain allowance to spend
- Check the allowance is indeed existing
- Switch to the other account in truffle ,truffle console --network regtestAccountTwo
- Then execute this transfer
1. How to link Truffle projects to Ganache?
- To link a project, enter the settings by clicking the gear icon in the upper right.
- You should be seeing the WORKSPACE settings pane; if not, you can get there by clicking the WORKSPACE tab in the top left.
- From here, there is a section labeled TRUFFLE PROJECTS. Beneath this box, click the button ADD PROJECT. A file selection popup will appear. Navigate to the folder of your Truffle project, and select the truffle-config.js or truffle.js configuration file. The file you pick must be either named truffle-config.js or truffle.js for Ganache to correctly load it.
- After selecting the file, you'll see it listed in the TRUFFLE PROJECTS section.
- After you're finished with adding projects you can click the SAVE AND RESTART (SAVE WORKSPACE if this is a new workspace) button in the top right. (insert screenshots that are similar to the ones on this page) https://www.trufflesuite.com/docs/ganache/truffle-projects/linking-a-truffle-project
2. Why are events not shown in Ganache?
Ganache'll try to decode the events that are defined in the contracts within the corresponding Truffle project. Check and make sure you've them ready.
- Make sure you have linked the corresponding Truffle project
- Make sure the contracts are already deployed. It should have a badge named deployed right next to it. (See screenshot below)
- Make sure the event is emitted in the contract's construction method. The reason is Ganache can only monitor events that has been fired on chain before.
- Make sure the contract's json file has the events field. The contract's json file can be found in path /build/.json. Open the json file and search for networks. You should see "33" under the "networks" key and also "events" under the "33". (See screenshot below). If the events field is empty, run migrate --reset to re-deploy the contract. This is due to an issue within the truffle development tool https://github.com/trufflesuite/truffle/issues/2224