2key
Published in

2key

Geth — A Local Ethereum Node

We prefer to use a Geth local Ethereum node. Installation packages are available for MacOSX and Windows.

We have discovered that Ganace and ganache-cli while useful might deviate from the standard Ethereum node behavior.

Get the genesis block, genesis.json

Initialise Gets

geth --datadir=./datadir init genesis.json

Create several accounts:

geth --datadir=./datadir account new

Store passwords, one password per line in a file, say password.geth.remix.txt

If you enter Gets console, with:

geth --datadir=./datadir console

And do:

miner.start()

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.

Run with:

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

Remix

Browser-based IDE — works in Safari and Chrome on MacOSX

http://remix.ethereum.org

Use the the http to work with Geth.

In the Run tab, select Provider to be Web3 Provider. Then select your local Geth node http://localhost:8545.

Remixd connects Remix to local files so you can edit in Remix or in your IDE.

npm install -g remixd

Run with:

remixd -s contracts

where contracts is your local contracts folder.

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.

After compiling a contract, click on Details to copy them manually

Using Openzeppelin

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:

github.com/OpenZeppelin/

So to import the Crowdsale contract, your import should be:

github.com/OpenZeppelin/openzeppelin-solidity/contracts/crowdsale/Crowdsale.sol

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 ./openzeppelin-solidity/contracts/crowdsale/Crowdsale.sol

Debugging

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.

  1. Create new account
  2. Transfer Ether between accounts

We discovered events emitted by contracts sometimes do not appear in Remix transactions log.

Common Errors

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.

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

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Yoram Kornatzky

Yoram Kornatzky

Entrepreneur, Building: Auction Events Platform for Creators, 25 years of development experience, Ph.D. Computer Science, https://yoramkornatzky.com