Code Monkey home page Code Monkey logo

web3-balance-go's Introduction

CircleCI

Web3 Balance

An extension of web3-go that is used for reading token or ether balances from the chain.

Example

eth, err := ethrpc.NewWithDefaults(ethClientURL)
b := balance.New(eth, 5)
block := fmt.Sprintf("0x%x", 7000000)

requests := []*balance.Request{
    &balance.Request{
        Address: "0xa838e871a02c6d883bf004352fc7dac8f781fed6",
        Currency:  balance.ETH,
        DefaultBlockParam:   block,
    },
    &balance.Request{
        Address: "0xa838e871a02c6d883bf004352fc7dac8f781fed6",
        Currency:  "0xBEB9eF514a379B997e0798FDcC901Ee474B6D9A1",
        DefaultBlockParam:   block,
    },
    &balance.Request{
        Address: "0xa838e871a02c6d883bf004352fc7dac8f781fed6",
        Currency:  "0xd26114cd6EE289AccF82350c8d8487fedB8A0C07",
        DefaultBlockParam:   block,
    },
    &balance.Request{
        Address: "0xa838e871a02c6d883bf004352fc7dac8f781fed6",
        Currency:  "0x8aa33a7899fcc8ea5fbe6a608a109c3893a1b8b2",
        DefaultBlockParam:   block,
    },
    &balance.Request{
        Address: "0xa838e871a02c6d883bf004352fc7dac8f781fed6",
        Currency: "0x0f5d2fb29fb7d3cfee444a200298f468908cc942",
        DefaultBlockParam:  block,
    },
}
rawBalances, err := b.GetRawSheet(requests)
if err != nil {
    fmt.Println(err)
    return
}
fmt.Println("--------------- Raw Balances -----------------")
spew.Dump(rawBalances)
// Outputs:
// --------------- Raw Balances -----------------
// (map[string]map[string]map[balance.Currency]string) (len=1) {
//  (string) (len=8) "0x6acfc0": (map[string]map[balance.Currency]string) (len=1) {
//   (string) (len=42) "0xa838e871a02c6d883bf004352fc7dac8f781fed6": (map[balance.Currency]string) (len=5) {
//    (balance.Currency) (len=3) "ETH": (string) (len=17) "0x21264e1ec881d8a",
//    (balance.Currency) (len=42) "0x8aa33a7899fcc8ea5fbe6a608a109c3893a1b8b2": (string) (len=66) "0x0000000000000000000000000000000000000000000000c328093e61ee400000",
//    (balance.Currency) (len=42) "0xBEB9eF514a379B997e0798FDcC901Ee474B6D9A1": (string) (len=66) "0x000000000000000000000000000000000000000000000001d4ccdee9a074c000",
//    (balance.Currency) (len=42) "0x0f5d2fb29fb7d3cfee444a200298f468908cc942": (string) (len=66) "0x00000000000000000000000000000000000000000000017dbe4e10a6870d635c",
//    (balance.Currency) (len=42) "0xd26114cd6EE289AccF82350c8d8487fedB8A0C07": (string) (len=66) "0x00000000000000000000000000000000000000000000000005afc055a2f44c2d"
//   }
//  }
// }
intBalances, err := b.GetIntSheet(requests)
if err != nil {
    fmt.Println(err)
    return
}
fmt.Println("--------------- big.Int Balances -----------------")
spew.Dump(intBalances)
// Outputs:
// --------------- big.Int Balances -----------------
// (map[string]map[string]map[balance.Currency]*big.Int) (len=1) {
//  (string) (len=8) "0x6acfc0": (map[string]map[balance.Currency]*big.Int) (len=1) {
//   (string) (len=42) "0xa838e871a02c6d883bf004352fc7dac8f781fed6": (map[balance.Currency]*big.Int) (len=5) {
//    (balance.Currency) (len=42) "0xd26114cd6EE289AccF82350c8d8487fedB8A0C07": (*big.Int)(0xc0002b0140)(409757565152676909),
//    (balance.Currency) (len=42) "0x8aa33a7899fcc8ea5fbe6a608a109c3893a1b8b2": (*big.Int)(0xc0002b0180)(3600000000000000000000),
//    (balance.Currency) (len=42) "0x0f5d2fb29fb7d3cfee444a200298f468908cc942": (*big.Int)(0xc0002b01c0)(7041922408306145321820),
//    (balance.Currency) (len=3) "ETH": (*big.Int)(0xc0002b0260)(149292659155410314),
//    (balance.Currency) (len=42) "0xBEB9eF514a379B997e0798FDcC901Ee474B6D9A1": (*big.Int)(0xc0002b02e0)(33780620000000000000)
//   }
//  }
// }
// 

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.