Coder Social home page Coder Social logo

geth-smart-contract's Introduction

Geth Smart Contract

This guide provides tutorials for using Geth to deploy and interact with smart contracts.

Prerequisite

1. Generate the ABI and BIN

We can use solc or tools like Hardhat or Foundry to generate the ABI and BIN files for our contracts.

Using solc

  1. Download solc using solc-select:
    git clone https://github.com/crytic/solc-select.git
    cd solc-select
    ./solc-select install
  2. Install the desired Solidity version:
    solc-select use 0.8.26 --always-install
  3. Navigate to the contract folder and run the command to generate the ABI and BIN files:
    solc --abi --bin -o build Storage.sol

2. Generate Go Files for Contract Deployment and Interaction

  1. Install the go-ethereum package, which is required for the abigen tool:
    go get github.com/ethereum/go-ethereum
  2. Install the abigen tool:
     go install github.com/ethereum/go-ethereum/cmd/abigen@latest
  3. Create a folder named storage for our Go package:
    mkdir storage
    cd storage
  4. Run the abigen command in the storage folder to generate the Go files for the storage package:
    abigen --abi=../contract/build/Storage.abi --bin=../contract/build/Storage.bin --pkg=storage --out=storage.go

3. Contract Deployment and Interaction

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

Notes

  • Run make clean if you encounter any Go module or package load errors.

geth-smart-contract's People

Contributors

zt-9 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.