Categorygithub.com/6boris/web3-go
module
0.0.10
Repository: https://github.com/6boris/web3-go.git
Documentation: pkg.go.dev

# README


Logo

Web3 Go

Ethereum Dapp Go API, inspired by web3.js.
Report Bug · Pull Request

WEBSITE LISTENSE

Introduction

This is the Ethereum Golang API which connects to the Generic JSON-RPC spec.

You need to run a local or remote Ethereum node to use this library.

Here is an open source case Web3 Studio reference under.

Logo

Client

export WEB3_GO_DEV_KEY_1="YOU_EVM_PRIVATE_KEY 1"
export WEB3_GO_DEV_KEY_2="YOU_EVM_PRIVATE_KEY 1"
go get github.com/6boris/web3-go
package main

import (
  "context"
  "fmt"
  "github.com/6boris/web3-go/client"
  clientModel "github.com/6boris/web3-go/model/client"
  "github.com/6boris/web3-go/pkg/pk"
  "github.com/ethereum/go-ethereum/common"
  "github.com/shopspring/decimal"
  "math/big"
  "os"
)

func main() {
  ctx := context.Background()
  evmSigners := make([]*clientModel.ConfEvmChainSigner, 0)
  for _, v := range []string{"WEB3_GO_DEV_KEY_1", "WEB3_GO_DEV_KEY_1"} {
    signer, loopErr := pk.TransformPkToEvmSigner(os.Getenv(v))
    if loopErr != nil {
      continue
    }
    evmSigners = append(evmSigners, signer)
  }
  ec, err := client.NewEvmClient(&clientModel.ConfEvmChainClient{
    TransportURL: "https://1rpc.io/matic",
    GasFeeRate:   decimal.NewFromFloat(2),
    GasLimitRate: decimal.NewFromFloat(1.5),
    Signers:      evmSigners,
  })

  nativeTx, err := ec.SendTransactionSimple(
    ctx,
    ec.GetAllSinners()[0], ec.GetAllSinners()[1],
    big.NewInt(1),
  )
  if err != nil {
    panic(err)
  }
  fmt.Println(fmt.Sprintf("Native Token Tx: %s", nativeTx.Hash()))

  erc20Tx, err := ec.ERC20Transfer(
    ctx,
    common.HexToAddress("0xc2132D05D31c914a87C6611C10748AEb04B58e8F"),
    ec.GetAllSinners()[0], ec.GetAllSinners()[1],
    decimal.NewFromFloat(0.000001).Mul(decimal.New(1, int32(6))).BigInt(),
  )
  if err != nil {
    panic(err)
  }
  fmt.Println(fmt.Sprintf("USDT Token Tx: %s", erc20Tx.Hash()))
}
/*
Output:
    Native Token Tx: 0xf3aa0e634357a222c39e8.......8f1a7e7d313db71827c3
    USDT Token Tx: 0xedd54d9e6bd3738880cd55........21aa69f06dba1e011625
*/

Development Trips

  • Client
    • Base Method
      • eth_chainId
      • web3_clientVersion
      • eth_gasPrice
      • eth_blockNumber
      • eth_getBalance
      • ...
    • Middleware
      • LoadBalance
      • Metrics
      • Grafana
      • CircuitBreaker
    • Business Cases
      • Web3 Studio
  • Other ...

Community

  • web3.js Ethereum JavaScript API.
  • Web3j Web3 Java Ethereum Ðapp API.
  • Web3.py A Python library for interacting with Ethereum.

Provider

Dev tool

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author