Blockchain Setting a Local Debugging Environment for Ethereum
Developing for Ethereum requires several moving parts. Our goal is to kickstart your debugging experience. Instructions apply to both MacOSX and Windows.
Geth - A Local Ethereum Node
We prefer to use a Geth local Ethereum node. Installation packages are available for MacOSX and Windows.
Get the genesis block, genesis.json
geth --datadir=./datadir init genesis.json
Create several accounts:
geth --datadir=./datadir account new
Store passwords, one password per line in a file, say
Mine Only When There Are Transactions
If you enter Gets console, with:
geth --datadir=./datadir console
You will get a flood of messages due to mining that will disrupt your debugging experience.
So, get the ethtxminer.js script that will cause Geth to mine only when a transaction arrived.
Running Geth for Development
geth --datadir=./datadir --nodiscover --rpc --rpcapi "db,personal,eth,net,web3,debug" --rpccorsdomain='*' --rpcaddr="localhost" --rpcport 8545 --unlock 0,1,2,3,4 --password password.geth.remix.txt --jspath . --preload ethtxminer.js console
Browser-based IDE - works in Safari and Chrome on MacOSX
Use the the
http to work with Geth.
In the Run tab, select Provider to be Web3 Provider. Then select your local Geth node
Remixd connects Remix to local files so you can edit in Remix or in your IDE.
npm install -g remixd
remixd -s contracts
contracts is your local contracts folder.
Open Local Files in Remix
In Remix, in the top left corner, click the link icon to connect to Remixd.
In the left sidebar, all your files appear under
localhost. Editing can be done either in IDE or in Remix. There is no
save action in Remix, so files are updated immediately in the file system.
Should be done with Geth console. No way to do it in Remix.
ABI and Bytecode
After compiling a contract, click on Details to copy them manually
OpenZeppelin is a well-known library for writing secure Smart Contracts on Ethereum. It provides a lot of standard contracts that you can inherit from.
Imports from Zeppelin in your contracts should be prefixed by:
So to import the
Crowdsale contract, your import should be:
This way Remix is able to fetch them and compile your contracts.
Alternatively, you can download openzeppelin-solidity to a subfolder of your local contracts folder, and refer to them with relative paths, such as
Most of your interaction with contracts, such as deployment, and calling of contract functions will be in Remix, using the Run tab. But, some things cannot be done in Remix, and some things do not work in Remix.
What Cannot be Done in Remix?
- Create new account
- Transfer Ether between accounts
What Does Not Work in Remix
We discovered events emitted by contracts sometimes do not appear in Remix transactions log.
Out of Gas in Remix
When Remix warns that a transaction will fail because of not enough gas, it usually, but not always mean that there is a bug in the contract function to be called. Or in the case of Deploy, in the contract constructor.
Oversized Data in Deploy
You should start by trying to refactor the contract code in order to reduce its size. This should be attempted before dealing with the block gas limit