Setting up the Client

Setting up the Ethereum client in Go is a fundamental step required for interacting with the blockchain. First import the ethclientgo-ethereum package and initialize it by calling Dial which accepts a provider URL.

You can connect to the infura gateway if you don't have an existing client. Infura manages a bunch of Ethereum [geth and parity] nodes that are secure, reliable, scalable and lowers the barrier to entry for newcomers when it comes to plugging into the Ethereum network.

client, err := ethclient.Dial("https://mainnet.infura.io")

You may also pass the path to the IPC endpoint file if you have a local instance of geth running.

client, err := ethclient.Dial("/home/user/.ethereum/geth.ipc")

Using the ethclient is a necessary thing you'll need to start with for every GoEthereum project and you'll be seeing this step a lot throughout this book.

Using Ganache

Ganache (formally known as testrpc) is an Ethereum implementation written in Node.js meant for testing purposes while developing dapps locally. Here we'll walk you through how to install it and connect to it.