ethutils

package module
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2024 License: GPL-3.0 Imports: 13 Imported by: 3

README

ethutils

Go test GitHub Tag Go Reference

High level Go wrapper for Ethereum, primarily targetting Celo.

Features:

  • Publishing smart contracts
  • Gas transfers
  • Smart contract interactions
  • Address conversion/parsing utilities
  • Grassroots Economics address loaders
  • Dump reverted tx reason
  • Batch balances scanner
  • Index iterator

Installation

$ go get github.com/grassrootseconomics/ethutils

License

LGPL-3.0

Documentation

Index

Constants

View Source
const (
	ErrInsufficientGas = "w3: call failed: insufficient funds for gas * price + value + gatewayFee"
	ErrGasPriceLow     = "w3: call failed: gasprice is less than gas price minimum floor"
	ErrNonceLow        = "w3: call failed: nonce too low"

	CeloContractMainnet   = "0x471EcE3750Da237f93B8E339c536989b8978a438"
	CeloContractTestnet   = "0xF194afDf50B03e69Bd7D057c1Aa9e10c9954E4C9"
	CUSDContractMainnet   = "0x765DE816845861e75A25fCA122bb6898B8B1282a"
	CUSDContractTestnet   = "0x874069Fa1Eb16D44d622F2e0Ca25eeA172369bC1"
	MinGasContractMainnet = "0xDfca3a8d7699D8bAfe656823AD60C17cb8270ECC"
	MinGasContractTestnet = "0xd0Bf87a5936ee17014a057143a494Dc5C5d51E5e"
)

Common error strings returned by v1 of celo-blockchain nodes.

View Source
const (
	EthereumMainnet int64 = 1
	EthereumSepolia int64 = 11155111

	OPMainnet int64 = 10
	OPSepolia int64 = 11155420

	CeloMainnet   int64 = 42220
	CeloAlfajores int64 = 44787
	CeloBaklava   int64 = 62320
)
View Source
const (
	AccountIndex    = "AccountIndex"
	CustodialProxy  = "CustodialRegistrationProxy"
	GasFaucet       = "GasFaucet"
	TrainingVoucher = "TrainingVoucher"
	TokenIndex      = "TokenIndex"
	PoolIndex       = "PoolIndex"
)
View Source
const (
	BalanceScannerContractAddress = "0xF62107c53a5b18646E823a21ed531ED934B1CE9E"
)

Variables

View Source
var (
	// SafeGasLimit is set to 350k gas units.
	SafeGasLimit = 350000
	// SafeGasFeeCap is set to 2x the current MinBaseFee of 5 gwei.
	SafeGasFeeCap = big.NewInt(10000000000)
	// SafeGasTipCap is set to 5 wei.
	SafeGasTipCap = big.NewInt(5)
)
View Source
var (
	ZeroAddress           = w3.A("0x0000000000000000000000000000000000000000")
	SarafuNetworkRegistry = w3.A("0xd1FB944748aca327a1ba036B082993D9dd9Bfa0C")
	CustodialRegistry     = w3.A("0x0cc9f4fff962def35bb34a53691180b13e653030")
)

Functions

func ChecksumAddress

func ChecksumAddress(address string) string

ChecksumAddress converts a mixed case hex address string to a checksumed one.

func HexToAddress

func HexToAddress(hexAddress string) common.Address

HexToAddress is similar to common.HexToAddress but converts to a checksumed address first. It is necessary to perform an address validation first before using HexToAddress e.g. with go-playground/validator.

func PrepareContractBytecodeData

func PrepareContractBytecodeData(contractBin string, contractABIJSON string, constructorArgs []any) ([]byte, error)

Types

type BatchIterator added in v1.2.0

type BatchIterator struct {
	// contains filtered or unexported fields
}

func (*BatchIterator) Next added in v1.2.0

func (iter *BatchIterator) Next(ctx context.Context) ([]common.Address, error)

type ContractExecutionTxOpts

type ContractExecutionTxOpts struct {
	ContractAddress common.Address
	InputData       []byte
	GasFeeCap       *big.Int
	GasTipCap       *big.Int
	GasLimit        uint64
	Nonce           uint64
}

type ContractPublishTxOpts

type ContractPublishTxOpts struct {
	ContractByteCode []byte
	GasFeeCap        *big.Int
	GasTipCap        *big.Int
	GasLimit         uint64
	Nonce            uint64
}

type GERegistry

type GERegistry map[string]common.Address

type GESmartContracts

type GESmartContracts map[string]bool

type GasTransferTxOpts

type GasTransferTxOpts struct {
	To        common.Address
	Value     *big.Int
	GasFeeCap *big.Int
	GasTipCap *big.Int
	Nonce     uint64
}

type Option

type Option func(c *Provider)

func WithClient

func WithClient(w3Client *w3.Client) Option

func WithSigner

func WithSigner(signer types.Signer) Option

type Provider

type Provider struct {
	Client *w3.Client
	Signer types.Signer
}

func NewProvider

func NewProvider(url string, chainID int64, opts ...Option) *Provider

func (*Provider) GetGESmartContracts

func (p *Provider) GetGESmartContracts(ctx context.Context, registries []string) (GESmartContracts, error)

func (*Provider) NewBatchIterator added in v1.2.0

func (p *Provider) NewBatchIterator(ctx context.Context, index common.Address) (*BatchIterator, error)

func (*Provider) RegistryMap

func (p *Provider) RegistryMap(ctx context.Context, registryAddress common.Address) (GERegistry, error)

RegistryMap auto-loads all well known custodial related smart contract addresses through the CICRegistry pointer contract.

func (*Provider) SignContractExecutionTx

func (p *Provider) SignContractExecutionTx(privateKey *ecdsa.PrivateKey, txData ContractExecutionTxOpts) (*types.Transaction, error)

func (*Provider) SignContractPublishTx

func (p *Provider) SignContractPublishTx(privateKey *ecdsa.PrivateKey, txData ContractPublishTxOpts) (*types.Transaction, error)

func (*Provider) SignGasTransferTx

func (p *Provider) SignGasTransferTx(privateKey *ecdsa.PrivateKey, txData GasTransferTxOpts) (*types.Transaction, error)

func (*Provider) SimulateRevertedTx

func (p *Provider) SimulateRevertedTx(ctx context.Context, txHash common.Hash, blockNumber *big.Int) (string, error)

SimulateRevertedTx attempts to simulate a reverted tx and dump its revert reason

func (*Provider) TokensBalance

func (p *Provider) TokensBalance(ctx context.Context, owner common.Address, tokenAddresses []common.Address) (TokenBalances, error)

type TokenBalances

type TokenBalances map[common.Address]*big.Int

Jump to

Keyboard shortcuts

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