synceth

command module
v0.0.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 5, 2024 License: MIT Imports: 1 Imported by: 0

README

ethgen - A smart contract development toolchain for Go

A simple yet powerful toolchain for Go based smart contract development

  • Compile solidity contracts and generate .abi and .bin artifacts.
  • Solidity compiler resolution and management.
  • Generate golang bindings from contract artifacts.
  • Generate contract fakes for smart contract testing.
  • Generate event handlers for smart contract indexing.

Compiling smart contracts

Create a generate.go file and add the following:

//go:generate go run -mod=mod github.com/withtally/synceth compile --outdir ./artifacts ./solidity

Generating bindings

Create a generate.go file and add the following:

//go:generate go run -mod=mod github.com/withtally/synceth bind --handlers --fakes --outdir ./bindings ./artifacts

Using Fakes

When --fakes is specified for binding generation, smart contract fakes will be generated based on the abi. A smart contract fake implements the full abi interface and adds additional methods for easily setting function return values and emitting events.

For example, a contract like:

contract Example {
    event ExampleEvent(string value);
    function getValue() public returns (string value);
}

Will generate a fake with interface:

contract FakeExample {
    event ExampleEvent(string value);
    function exampleValue() public returns (string value);

    function fakeSetExampleValue(string value);
    function fakeEmitExampleEvent(string value);
}

The fake methods can be used to set the return value of the exampleValue function and to easily emit the ExampleEvent.

Using the fake:

address, tx, c, err := bindings.DeployFakeExample(auth, eth)
if err != nil {
    t.Fatalf("Deploying contract: %v", err)
}

if _, err := c.FakeSetExampleValue(auth, "tally"); err != nil {
    t.Fatalf("Setting value: %v", err)
}

eth.Commit()

v, err := c.exampleValue(nil)
if err != nil {
    t.Fatalf("Getting value: %v", err)
}

println(v) // tally

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
testexample

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL