8000 GitHub - metachris/eth-go-bindings at v0.3.0
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Go bindings for Ethereum smart contracts: ERC20, ERC165 and ERC721, ERC777, ERC1155

License

Notifications You must be signed in to change notification settings

metachris/eth-go-bindings

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go bindings for Ethereum smart contracts

Currently implemented:

Notes:

Versions used to build the bindings:

  • go1.16.3
  • abigen version 1.10.4-unstable
  • solc: 0.8.4+commit.c7e474f2.Emscripten.clang

Quickstart

In Go:

package main

import (
	"fmt"
	"log"

	"github.com/ethereum/go-ethereum/common"
	"github.com/ethereum/go-ethereum/ethclient"
	"github.com/metachris/erc721-go-bindings/erc165"
	"github.com/metachris/erc721-go-bindings/erc721"
)

func main() {
	// Connect to a geth node (when using Infura, you need to use your own API key)
	conn, err := ethclient.Dial("https://mainnet.infura.io/v3/API_KEY")
	if err != nil {
		log.Fatalf("Failed to connect to the Ethereum client: %v", err)
	}

	// Instantiate the ERC721 contract for Uniswap V3: Positions NFT
	address := common.HexToAddress("0xC36442b4a4522E871399CD717aBDD847Ab11FE88")
	token, err := erc721.NewErc721(address, conn)
	if err != nil {
		log.Fatalf("Failed to instantiate a Token contract: %v", err)
	}

	// Access token properties
	name, err := token.Name(nil)
	if err != nil {
		log.Fatalf("Failed to retrieve token name: %v", err)
	}
	fmt.Println("Token name:", name)

    // Invoke the ERC165 SupportsInterface method
	supportsMetadata, err := token.SupportsInterface(nil, erc165.InterfaceIdErc721Metadata)
	if err != nil {
		log.Fatalf("Failed to retrieve supportsInterface: %v", err)
	}
	fmt.Println("Supports ERC721Metadata extension:", supportsMetadata)
}

Get dependencies and run:

go mod tidy
go run .

Smart contract & building

Source: Erc721.sol

Build the contract:

# Install dependencies
yarn init -y
yarn add truffle @openzeppelin/contracts @chainsafe/truffle-plugin-abigen

yarn truffle compile
yarn truffle run abigen Erc20 Erc165 Erc721
abigen --bin=abigenBindings/bin/Erc20.bin --abi=abigenBindings/abi/Erc20.abi --pkg=erc20 --out=erc20/erc20.go
abigen --bin=abigenBindings/bin/Erc165.bin --abi=abigenBindings/abi/Erc165.abi --pkg=erc165 --out=erc165/erc165.go
abigen --bin=abigenBindings/bin/Erc721.bin --abi=abigenBindings/abi/Erc721.abi --pkg=erc721 --out=erc721/erc721.go

About

Go bindings for Ethereum smart contracts: ERC20, ERC165 and ERC721, ERC777, ERC1155

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Languages

0