This guide provides tutorials for using Geth to deploy and interact with smart contracts.
We can use solc
or tools like Hardhat or Foundry to generate the ABI and BIN files for our contracts.
- Download
solc
using solc-select:git clone https://github.com/crytic/solc-select.git cd solc-select ./solc-select install
- Install the desired Solidity version:
solc-select use 0.8.26 --always-install
- Navigate to the
contract
folder and run the command to generate the ABI and BIN files:solc --abi --bin -o build Storage.sol
- Install the
go-ethereum
package, which is required for theabigen
tool:go get github.com/ethereum/go-ethereum
- Install the
abigen
tool:go install github.com/ethereum/go-ethereum/cmd/abigen@latest
- Create a folder named
storage
for our Go package:mkdir storage cd storage
- Run the
abigen
command in thestorage
folder to generate the Go files for thestorage
package:abigen --abi=../contract/build/Storage.abi --bin=../contract/build/Storage.bin --pkg=storage --out=storage.go
The generated storage.go
file provides the DeployStorage()
function to deploy the contract, as well as functions to interact with it.
To call the store()
function in the Storage
contract, use the generated Store()
function in the storage.go
file.
Refer to the example in storage/storage_test.go
for contract deployment and interaction.
In this test, we use Anvil to start a local ethereum testnet node. Ensure you have Foundry installed before running the test:
make test
- Run
make clean
if you encounter any Go module or package load errors.