Web3 - Day 3: Deploying Smart Contracts with Geth
As with many a personal endeavour, things tend to lose some steam after the initial zeal and enthusiasm for something new. Very much like a new gym or programme or eating plan... so Day 3 took a bit of a detour and some time to smell the roses.
I initially wanted to do a full post about how to set up IntelliJ for developing and debugging Solidity end to end but I quickly realised that many of the lego blocks needed to make this work hasn't seen any love from the community since 2018.?
There are some remnants of EthereumJ that were used in the past to spin up a local EVM that one could interact with via the IntelliJ debugger interface but it’s long gone - you could probably compile the module from source code and tinker a bit to get it working but after -wasting - spending an evening researching I figured if it’s that difficult to find something this basic then I’m barking up the wrong tree.?
I’m hopeful that there are more integrated approaches to debugging Solidity code locally and I’ll be sure to share it when I find it.
Some of the ancient artefacts I tried to stitch together:
- Solidity Intellij Plugin?- Limited language support
- Solidity Intellij Debugger module - DEPRECATED
- EthereumJ Java-based EVM/ client - DEPRECATED
Anyway - I decided to deviate from my plotted course and make a stop in GoLand. Fair warning, my Go is a bit rusty - not in a good way! I converted my Day 2 lottery contact compilation and testing infrastructure to Go. Turns out, Go has really great Ethereum ecosystem support and uses the same ingredients from my previous NodeJS-based deployments.
- Ganache for local testing
- Geth - the defacto Ethereum client (that most nodes are running)
- Abigen - CLI tool to generate boilerplate code for you to interact with your contract in Go
Unfortunately, the Solidity compiler Go bindings have not been maintained so I resorted to calling the CLI tools from code instead. It’s not the most portable solution and it’s not pretty, but for now, it’s convenient and I had fun stringing it together.
I completely disregarded abigen at first and tried to find a web3 client equivalent of what I have been using in Node thus far. I tinkered with this Go client just to get going and I managed to interact with a contract instance I deployed earlier.
领英推è
What struck me at this point was how programmable and accessible the compilation and deployment were made in the NodeJS web3 tooling. It's really powerful to be able to pull in your Solidity code as a string, compile it and push it to a chain without leaving your code.
The other thing that struck me (felt more like a blow to the head) was how verbose Go code can be (or strongly typed languages for that matter). Believe it or not, I’m an ex-java developer and this still got me! But just consider the Go snippet below used to set the value of ETH/Wei sent to a wallet:
value? ? = new(big.Int).Mul(big.NewInt(1), big.NewInt(params.Ether))
- I'm probably nitpicking here
I won’t lie, I struggled a bit to piece this together but it helps to have a Go expert in the house ?? Clara van Staden
New tech I got to play with today
- Geth to interact with the blockchain. It’s slightly more low-level than the web3 node equivalent but manageable.
- abigen to generate a Go client to interact with my lottery contract.
- Cobra for creating an easy command-line interface for the Go app (instead of writing proper tests ?? - I’ll do that later)
As usual, you can find the code for day 3?here and a special mention to Marius van der Wijden for sharing such great content to learn how to use Geth!
#solidity?#ether?#ethereummerge?#smartcontract?#smartcontracts?#crypto?#web3?#remix?#metamask?#decentralization?#go #golang #learninggolang #geth #EthereumJ
Originally posted on my blog at?webler.co.za
Full Stack Software Engineer | Kubernetes | AWS | Java | Angular
2 年No tests?!…you’re lucky there’s no pull-requests