Giter Site home page Giter Site logo

buddy's Introduction

Buddy

This project is a work in progress and I'm adding commands as I need them.

Interface focused go bindings for ethereum contracts. Allows for easy mock testing for smart contracts in go (!), amongst other quality of life improvements for those of us who prefer to use go to interact with smart contracts.

Dependencies

go-ethereum

Usage

Smart contract binding generation using abigen sub command

Use the abigen command to generate go bindings from an abi file. If you include a binary of the compiled contract, then a deployment method is also generated. This command uses much of the same code as the abigen cli command included in go-ethereum

buddy abigen "path/to/abi/and/maybe/a/bin" -p packageName

or in the working directory with a specified abi or bin file

buddy abigen --pkg=packageName --abi=contract.abi --bin=contract.bin

Multiple contracts can be generated into the same package if so desired.

Cool Stuff

While generating go bindings for smart contracts is nothing new, these bindings allow one to write go interfaces for generated code.

package main

import (
    "github.com/your-username/coin" // import your generated bindings
    "github.com/ethereum/go-ethereum/accounts/abi"
    "github.com/ethereum/go-ethereum/common"
)

type Erc20 interface {
    Approve(opts *bind.TransactOpts, usr common.Address, wad *big.Int) (*types.Transaction, error)
    Transfer(opts *bind.TransactOpts, dst common.Address, wad *big.Int) (*types.Transaction, error)
}

func Erc20Procedure(erc Erc20) {
    // do stuff with erc20s
}

func main() { 
    c, err := uniswap.NewUniswapExchange(common.HexToAddress("0x6b175474e89094c44da98b954eedeac495271d0f"))
    if err != nil {
        log.Fatal(err)
    }

    Erc20Procedure(c)

    // while still retaining the ability to call contract specific methods without a seperate instance
    c.ContractSpecificMethodNotInTheInterface(opts, new(big.Int).SetFromString("12345678910111213141516"))
}

Doing something similar with the official abigen command would require twice the compiling, code generating, and keeping track of two contract instances.

buddy's People

Contributors

evan-forbes avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

haiheipijuan

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.