npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@divergencetech/ethier

v0.55.0

Published

Golang and Solidity SDK to make Ethereum development ethier

Downloads

154

Readme

testing linting

Motivation

ethier (pronounced "easier" with a lisp) intends to:

  1. Gradually replace the reliance on JavaScript in Ethereum development with Go as it is (a) faster due to in-process backends for testing, and (b) more robust due to type safety. Although unlikely, ethier's "North Star" is a replacement for Truffle/Hardhat.
  2. Provide reusable Solidity functionality not covered by OpenZeppelin and, where appropriate, provide respective Go bindings with round-trip testing.

Versioning, stability, and production readiness

ethier uses Semantic Versioning 2.0.0. As the major version is currently zero, the API is open to change without warning.

Contracts are very thoroughly tested but have not been subject to audit nor widespread use. Early adopters are not only welcome, but will be greatly appreciated.

Why NPM if we're moving away from JavaScript?

Although ethier intends to use Go as much as possible, users may not, and NPM is the de facto standard in Ethereum development. While this gives us a weird mashup of go.mod and package.json, it's fit for purpose.

Getting started

Installation

  1. Assuming solc and go are already installed:
go install github.com/divergencetech/ethier/ethier@latest
go install github.com/ethereum/go-ethereum/cmd/abigen@latest
  1. Ensure that the go/bin directory is in your $PATH. This can be confirmed by running which ethier && echo GOOD; if the word GOOD is printed then the ethier binary has been found.

Usage

Generating Go bindings

This example assumes that the file is in the contracts directory with all Solidity files present. If moving to a different directory, simply change the relative paths.

package contracts

//go:generate ethier gen MyContract.sol

Run go generate ./... to generate Go bindings, including deployment functions. The above example will generate contracts/generated.go with bindings to MyContract.sol. These bindings can be used for (1) testing and/or (2) connecting to a gateway node (e.g. Infura or Alchemy), depending on the ContractBackend being used:

  1. For tests, use ethier's ethtest.SimulatedBackend, which extends the standard geth simulator with convenience behaviour like auto commitment of transactions.

  2. For a gateway, use the ethclient package.

Example test

package contracts

import (
   "testing" 

   "github.com/divergencetech/ethier/ethtest"
)

// The test backend creates as many accounts as needed, each representing a different
// "actor" in the test scenarios. A useful pattern is to simply enumerate them the iota
// pattern (which automatically increments) and add a `numAccounts` at the end.
const (
   deployer = iota
   vandal
   numAccounts
)

func TestMyContract(t *testing.T){
   sim := ethtest.NewSimulatedBackend(t, numAccounts)

   // The DeployMyContract function is automatically generated when running `go generate`.
   // addr and tx generally aren't useful, but are documented here for completeness
   addr, tx, contract, err := DeployMyContract(sim.Acc(deployer), sim /*,,, [constructor arguments]*/)
   if err != nil {
      t.Fatalf("DeployMyContract(%v) error %v", …, err)
   }

   // NOTE: If connecting to a deployed contract above, use NewMyContract() and substitute `sim`
   // for an *ethclient.Client`.

   t.Run("protect something sensitive", func(t *testing.T){
      // The test-actor pattern in the consts above makes tests self-documenting.
      _, err := contract.DoSomethingImportant(sim.Acc(vandal))
      // Confirm that there's an error because the vandal shouldn't be allowed to do anything
      // important!!! See the ethtest/revert package.
   })
}

See tests/ for further usage examples. Remember to add generated.go to your .gitignore file.