Skip to content

ethclient extension, which supports more features, e.g., timer transactions, ticker transactions, batch transactions and sequenced transctions.

License

Notifications You must be signed in to change notification settings

ivanzzeth/ethclient

Repository files navigation

ethclient

Description

Extension ethclient.

Prerequisites

golang

Feautres

  • Schedule message
  • Sequence message
  • Protect message
  • Nonce management
  • Concurrent Transaction in Safe Multisig Wallets
  • Multiple rpc url supported

Quick Start

package main

import (
	"fmt"
	"time"

	"github.com/ivanzzeth/ethclient"
	"github.com/ivanzzeth/ethclient/message"
	"github.com/ivanzzeth/ethclient/tests/helper"
)

func main() {
	client, err := ethclient.Dial("http://localhost:8545")
	if err != nil {
		panic(err)
	}
	defer client.Close()

	go func() {
		client.ScheduleMsg((&message.Request{
			From:      helper.Addr,
			To:        &helper.Addr,
			StartTime: time.Now().Add(5 * time.Second).UnixNano(),
		}).SetRandomId())

		client.ScheduleMsg((&message.Request{
			From: helper.Addr,
			To:   &helper.Addr,
			// StartTime:      time.Now().Add(5 * time.Second).UnixNano(),
			ExpirationTime: time.Now().UnixNano() - int64(5*time.Second),
		}).SetRandomId())

		client.ScheduleMsg((&message.Request{
			From:           helper.Addr,
			To:             &helper.Addr,
			ExpirationTime: time.Now().Add(10 * time.Second).UnixNano(),
			Interval:       2 * time.Second,
		}).SetRandomId())

		time.Sleep(20 * time.Second)
		client.CloseSendMsg()
	}()

	for resp := range client.Response() {
		fmt.Println("execution resp: ", resp)
	}
}

Concurrent Transaction Management in Safe Multisig Wallets

The Safe multisig contract also uses a nonce. Our solution manages this nonce off-chain. Now you can submit multiple transactions at once - no need to wait for confirmations.

The current implementation uses Safe v1.3, but you can build your own for different Safe contract versions.

func BatchSendSafeTx(from common.Address, builder gnosissafe.SafeTxBuilder, deliverer gnosissafe.SafeTxDeliverer, params []gnosissafe.SafeTxParam) {

	safeContractAddress, _ := builder.GetContractAddress()

	for _, param := range params {
		callData, _, safeNonce, err := builder.Build(param)
		if err != nil {
			// Handle error
			return
		}

		req := message.Request{
			From:     from,
			To:       &safeContractAddress,
			Gas:      500000, // ensure gas meets the minimum requirement for successful Safe contract execution (avoiding reverts).
			Data:     callData,
		}
		err = deliverer.Deliver(&req, safeNonce)
		if err != nil {
			// Handle error
			return
		}
	}
}

Setup local node for testing

you should install foundry before running the script below:

./cmd/run_test_node.sh

License

The ethclient library is licensed under the GNU General Public License v3.0, also included in our repository in the COPYING.LESSER file.

About

ethclient extension, which supports more features, e.g., timer transactions, ticker transactions, batch transactions and sequenced transctions.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages