eth

package module
v0.0.0-...-40564c6 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2025 License: Apache-2.0 Imports: 24 Imported by: 25

README

Ethereum API library for Go

Documentation

Overview

Example (Rpc_getBlockByNumber)
client := rpc.NewClient(getRPCURL())
blockRef := rpc.LatestBlock
if os.Getenv("ETH_GO_RPC_BLOCK_NUMBER") != "" {
	var err error
	blockNumber, err := strconv.ParseUint(os.Getenv("ETH_GO_RPC_BLOCK_NUMBER"), 0, 64)
	if err != nil {
		panic(fmt.Errorf("parse custom block number info: %w", err))
	}

	blockRef = rpc.BlockNumber(blockNumber)
}

result, err := client.GetBlockByNumber(context.Background(), blockRef, rpc.WithGetBlockFullTransaction())
if err != nil {
	panic(fmt.Errorf("get block by number %s: %w", blockRef, err))
}

bytes, err := rpc.MarshalJSONRPC(result)
if err != nil {
	panic(fmt.Errorf("json marshal response: %w", err))
}

fmt.Println(string(bytes))

Index

Examples

Constants

This section is empty.

Variables

View Source
var ETHToken = &Token{
	Name:     "Ethereum",
	Symbol:   "ETH",
	Address:  nil,
	Decimals: 18,
}
View Source
var KnownSignatures = map[string]string{}/* 149637 elements not displayed */

Functions

func B

func B(input string) []byte

func CanonicalHex

func CanonicalHex(input string) string

CanonicalHex receives an input and return it's canonical form, i.e. the single unique well-formed which in our case is an all-lower case version with even number of characters.

The only differences with `SanitizeHexInput` here is an additional call to `strings.ToLower` before returning the result.

func ConcatHex

func ConcatHex(with0x bool, in ...string) (out string)

ConcatHex concatenates sanitized hex strings

func DecimalsInBigInt

func DecimalsInBigInt(decimal uint32) *big.Int

func DeclarationTypeNames

func DeclarationTypeNames() []string

DeclarationTypeNames returns a list of possible string values of DeclarationType.

func Has0xPrefix

func Has0xPrefix(input string) bool

func Keccak256

func Keccak256(data ...[]byte) []byte

func MustDecodeString

func MustDecodeString(hexStr string) []byte

func PrefixedHex

func PrefixedHex(input string) string

PrefixedHex is CanonicalHex but with 0x prefix

func PrettifyBigIntWithDecimals

func PrettifyBigIntWithDecimals(in *big.Int, precision, truncateDecimalCount uint) string

func SanitizeHex

func SanitizeHex(input string) string

SanitizeHex removes the prefix `0x` if it exists and ensures there is an even number of characters in the string, padding on the left of the string is it's not the case.

func StateMutabilityNames

func StateMutabilityNames() []string

StateMutabilityNames returns a list of possible string values of StateMutability.

func TransactionTypeNames

func TransactionTypeNames() []string

TransactionTypeNames returns a list of possible string values of TransactionType.

func TypeKindNames

func TypeKindNames() []string

TypeKindNames returns a list of possible string values of TypeKind.

Types

type ABI

type ABI struct {
	LogEventsMap    map[string][]*LogEventDef
	FunctionsMap    map[string][]*MethodDef
	ConstructorsMap map[string][]*MethodDef

	LogEventsByNameMap    map[string][]*LogEventDef
	FunctionsByNameMap    map[string][]*MethodDef
	ConstructorsByNameMap map[string][]*MethodDef
}

ABI is our custom internal definition of a contract's ABI that bridges the information between the two ABI like formats for contract's, i.e. `.abi` file and AST file as output by `solc` compiler.

FIXME: Our internal structure is wrong because multiple functions and multiple events can exist under the same name. This is problematic right now because we use a one level mapping and only the "last seen" event wins. This will require a refactor and will trickle down in a few places.

func ParseABI

func ParseABI(abiFilePath string) (*ABI, error)

func ParseABIFromBytes

func ParseABIFromBytes(content []byte) (*ABI, error)

func ParseAST

func ParseAST(astFilepath string) *ABI

func (*ABI) FindFunction deprecated

func (a *ABI) FindFunction(functionHash []byte) *MethodDef

Deprecated: Use FindFunctionByHash

func (*ABI) FindFunctionByHash

func (a *ABI) FindFunctionByHash(functionHash []byte) *MethodDef

FindFunctionByHash finds the function with the give `hash`.

func (*ABI) FindFunctionByName

func (a *ABI) FindFunctionByName(name string) *MethodDef

FindFunctionByName finds the first function with the give `name`. Multiple functions could have the same name, use `FindFunctionsByName` to get them all.

func (*ABI) FindFunctionsByName

func (a *ABI) FindFunctionsByName(name string) []*MethodDef

FindFunctionsByName returns **all** functions with the give `name`.

func (*ABI) FindLog

func (a *ABI) FindLog(topic []byte) *LogEventDef

Deprecated Use FindLogByTopic

func (*ABI) FindLogByName

func (a *ABI) FindLogByName(name string) *LogEventDef

FindLogByName finds the first log with the give `topic`. Multiple events could have the same topic, use `FindLogsByName` to get them all.

func (*ABI) FindLogByTopic

func (a *ABI) FindLogByTopic(topic []byte) *LogEventDef

FindLogByTopic finds the first log with the give `topic`. Multiple events could have the same topic, use `FindLogByTopic` to get them all.

func (*ABI) FindLogsByName

func (a *ABI) FindLogsByName(name string) []*LogEventDef

FindLogsByName returns **all** logs with the give `topic`.

func (*ABI) FindLogsByTopic

func (a *ABI) FindLogsByTopic(topic []byte) []*LogEventDef

FindLogByTopic returns **all** logs with the give `topic`.

type Address

type Address []byte

func MustNewAddress

func MustNewAddress(input string) Address

MustNewAddress is exactly like NewAddress but it panics if an error occurrs.

See [NewAdress] for detaiks.

func MustNewAddressLoose

func MustNewAddressLoose(input string) Address

MustNewAddressLoose is exactly like NewAddressLoose but it panics if an error occurrs.

See NewAddressLoose for detaiks.

func NewAddress

func NewAddress(input string) (Address, error)

NewAddress creates an address where the input **must** contain exactly 20 bytes.

If the actual input is not an hexadecimal string, an error is returned or the decoded lenght is not exactly 20 bytes, an error is returned.

func NewAddressLoose

func NewAddressLoose(input string) (Address, error)

NewAddressLoose creates an address where the input can contain more than 20 bytes (truncated) or less than 20 bytes (left as-is).

If the actual input is not an hexadecimal string, an error is returned.

func (Address) Bytes

func (a Address) Bytes() []byte

func (Address) ID

func (a Address) ID() uint64

func (Address) MarshalJSON

func (a Address) MarshalJSON() ([]byte, error)

func (Address) MarshalJSONRPC

func (a Address) MarshalJSONRPC() ([]byte, error)

func (Address) MarshalText

func (a Address) MarshalText() ([]byte, error)

func (Address) Pretty

func (a Address) Pretty() string

func (Address) String

func (a Address) String() string

func (*Address) UnmarshalJSON

func (a *Address) UnmarshalJSON(data []byte) error

func (*Address) UnmarshalText

func (a *Address) UnmarshalText(data []byte) error

type AddressArray

type AddressArray []Address

func (AddressArray) At

func (a AddressArray) At(index uint64, value interface{})

type AddressType

type AddressType struct {
}

func (AddressType) IsDynamic

func (t AddressType) IsDynamic() bool

func (AddressType) Kind

func (a AddressType) Kind() TypeKind

func (AddressType) Name

func (t AddressType) Name() string

type ArrayType

type ArrayType struct {
	// ElementType represents the underlying stored element
	ElementType SolidityType
}

func (ArrayType) IsDynamic

func (t ArrayType) IsDynamic() bool

func (ArrayType) Kind

func (t ArrayType) Kind() TypeKind

func (ArrayType) Name

func (t ArrayType) Name() string

type BigIntArray

type BigIntArray []*big.Int

func (BigIntArray) At

func (a BigIntArray) At(index uint64, value interface{})

type BoolArray

type BoolArray []bool

func (BoolArray) At

func (a BoolArray) At(index uint64, value interface{})

type BooleanType

type BooleanType struct {
}

func (BooleanType) IsDynamic

func (t BooleanType) IsDynamic() bool

func (BooleanType) Kind

func (a BooleanType) Kind() TypeKind

func (BooleanType) Name

func (t BooleanType) Name() string

type Bytes

type Bytes []byte

func MustNewBytes

func MustNewBytes(input string) Bytes

func NewBytes

func NewBytes(input string) (Bytes, error)

func (Bytes) Bytes

func (h Bytes) Bytes() []byte

func (Bytes) ID

func (h Bytes) ID() uint64

func (Bytes) MarshalJSON

func (h Bytes) MarshalJSON() ([]byte, error)

func (Bytes) MarshalJSONRPC

func (h Bytes) MarshalJSONRPC() ([]byte, error)

func (Bytes) MarshalText

func (h Bytes) MarshalText() ([]byte, error)

func (Bytes) Pretty

func (h Bytes) Pretty() string

func (Bytes) String

func (h Bytes) String() string

func (*Bytes) UnmarshalJSON

func (h *Bytes) UnmarshalJSON(data []byte) error

func (*Bytes) UnmarshalText

func (h *Bytes) UnmarshalText(data []byte) error

type BytesType

type BytesType struct {
}

func (BytesType) IsDynamic

func (t BytesType) IsDynamic() bool

func (BytesType) Kind

func (t BytesType) Kind() TypeKind

func (BytesType) Name

func (t BytesType) Name() string

type DeclarationType

type DeclarationType int

ENUM(

Function
Constructor
Receive
Fallback
Event
Error

)

const (
	// DeclarationTypeFunction is a DeclarationType of type Function.
	DeclarationTypeFunction DeclarationType = iota
	// DeclarationTypeConstructor is a DeclarationType of type Constructor.
	DeclarationTypeConstructor
	// DeclarationTypeReceive is a DeclarationType of type Receive.
	DeclarationTypeReceive
	// DeclarationTypeFallback is a DeclarationType of type Fallback.
	DeclarationTypeFallback
	// DeclarationTypeEvent is a DeclarationType of type Event.
	DeclarationTypeEvent
	// DeclarationTypeError is a DeclarationType of type Error.
	DeclarationTypeError
)

func ParseDeclarationType

func ParseDeclarationType(name string) (DeclarationType, error)

ParseDeclarationType attempts to convert a string to a DeclarationType

func (DeclarationType) MarshalText

func (x DeclarationType) MarshalText() ([]byte, error)

MarshalText implements the text marshaller method

func (DeclarationType) String

func (x DeclarationType) String() string

String implements the Stringer interface.

func (*DeclarationType) UnmarshalText

func (x *DeclarationType) UnmarshalText(text []byte) error

UnmarshalText implements the text unmarshaller method

type Decoder

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

func NewDecoder

func NewDecoder(input []byte) *Decoder

func NewDecoderFromString

func NewDecoderFromString(input string) (*Decoder, error)

func (*Decoder) Read

func (d *Decoder) Read(typeName string) (interface{}, error)

func (*Decoder) ReadAddress

func (d *Decoder) ReadAddress() (out Address, err error)

func (*Decoder) ReadBigInt

func (d *Decoder) ReadBigInt() (out *big.Int, err error)

func (*Decoder) ReadBool

func (d *Decoder) ReadBool() (out bool, err error)

func (*Decoder) ReadBuffer

func (d *Decoder) ReadBuffer(byteCount uint64) ([]byte, error)

func (*Decoder) ReadBytes

func (d *Decoder) ReadBytes() ([]byte, error)

func (*Decoder) ReadFixedBytes

func (d *Decoder) ReadFixedBytes(byteCount uint64) ([]byte, error)

func (*Decoder) ReadMethod

func (d *Decoder) ReadMethod() (out string, err error)

func (*Decoder) ReadMethodCall

func (d *Decoder) ReadMethodCall() (*MethodCall, error)

func (*Decoder) ReadOutput

func (d *Decoder) ReadOutput(parameters []*MethodParameter) (out []interface{}, err error)

func (*Decoder) ReadString

func (d *Decoder) ReadString() (out string, err error)

func (*Decoder) ReadUint64

func (d *Decoder) ReadUint64() (out uint64, err error)

func (*Decoder) SetBytes

func (d *Decoder) SetBytes(input []byte) *Decoder

func (*Decoder) String

func (d *Decoder) String() string

type Encoder

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

func NewEncoder

func NewEncoder() *Encoder

func (*Encoder) Buffer

func (e *Encoder) Buffer() []byte

func (*Encoder) String

func (e *Encoder) String() string

func (*Encoder) Write

func (e *Encoder) Write(parameter *MethodParameter, in interface{}) error

func (*Encoder) WriteLogData

func (e *Encoder) WriteLogData(parameters []*LogParameter, data []interface{}) error

func (*Encoder) WriteLogParameter

func (e *Encoder) WriteLogParameter(parameter *LogParameter, in interface{}) error

func (*Encoder) WriteMethodCall

func (e *Encoder) WriteMethodCall(method *MethodCall) error

func (*Encoder) WriteParameters

func (e *Encoder) WriteParameters(parameters []*MethodParameter, data []interface{}) error

type ErrDecoding

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

func NewErrDecoding

func NewErrDecoding(message string, args ...interface{}) *ErrDecoding

func (*ErrDecoding) Error

func (e *ErrDecoding) Error() string

type FixedSizeArrayType

type FixedSizeArrayType struct {
	// ElementType represents the underlying stored element
	ElementType SolidityType
	// Length is the number of fixed element this array contains
	Length uint
}

func (FixedSizeArrayType) IsDynamic

func (t FixedSizeArrayType) IsDynamic() bool

func (FixedSizeArrayType) Kind

func (t FixedSizeArrayType) Kind() TypeKind

func (FixedSizeArrayType) Name

func (t FixedSizeArrayType) Name() string

type FixedSizeBytesType

type FixedSizeBytesType struct {
	// ByteSize is the number of bytes taken by this type, range of values is between 1 and 32 (inclusive)
	ByteSize uint
}

func (FixedSizeBytesType) IsDynamic

func (t FixedSizeBytesType) IsDynamic() bool

func (FixedSizeBytesType) Kind

func (t FixedSizeBytesType) Kind() TypeKind

func (FixedSizeBytesType) Name

func (t FixedSizeBytesType) Name() string

type FixedUint64

type FixedUint64 uint64

FixedUint64 is a fixed size uint64, marshalled as a fixed 8 bytes big endian

func (*FixedUint64) MarshalJSONRPC

func (n *FixedUint64) MarshalJSONRPC() ([]byte, error)

func (*FixedUint64) UnmarshalText

func (b *FixedUint64) UnmarshalText(text []byte) error

type Hash

type Hash []byte

func MustNewHash

func MustNewHash(input string) Hash

func NewHash

func NewHash(input string) (Hash, error)

func (Hash) Bytes

func (h Hash) Bytes() []byte

func (Hash) ID

func (h Hash) ID() uint64

func (Hash) MarshalJSON

func (h Hash) MarshalJSON() ([]byte, error)

func (Hash) MarshalJSONRPC

func (h Hash) MarshalJSONRPC() ([]byte, error)

func (Hash) MarshalText

func (h Hash) MarshalText() ([]byte, error)

func (Hash) Pretty

func (h Hash) Pretty() string

func (Hash) String

func (h Hash) String() string

func (*Hash) UnmarshalJSON

func (h *Hash) UnmarshalJSON(data []byte) error

func (*Hash) UnmarshalText

func (h *Hash) UnmarshalText(data []byte) error

type Hex

type Hex []byte

func MustNewHex

func MustNewHex(input string) Hex

func NewHex

func NewHex(input string) (Hex, error)

func (Hex) Bytes

func (h Hex) Bytes() []byte

func (Hex) ID

func (h Hex) ID() uint64

func (Hex) MarshalJSON

func (h Hex) MarshalJSON() ([]byte, error)

func (Hex) MarshalJSONRPC

func (h Hex) MarshalJSONRPC() ([]byte, error)

func (Hex) MarshalText

func (h Hex) MarshalText() ([]byte, error)

func (Hex) Pretty

func (h Hex) Pretty() string

func (Hex) String

func (h Hex) String() string

func (*Hex) UnmarshalJSON

func (h *Hex) UnmarshalJSON(data []byte) error

func (*Hex) UnmarshalText

func (h *Hex) UnmarshalText(data []byte) error

type Int

type Int int

func (*Int) UnmarshalText

func (b *Int) UnmarshalText(text []byte) error

type Int16

type Int16 int16

func (*Int16) UnmarshalText

func (b *Int16) UnmarshalText(text []byte) error

type Int32

type Int32 int32

func (*Int32) UnmarshalText

func (b *Int32) UnmarshalText(text []byte) error

type Int64

type Int64 int64

func (*Int64) UnmarshalText

func (b *Int64) UnmarshalText(text []byte) error

type Int8

type Int8 int8

func (*Int8) UnmarshalText

func (b *Int8) UnmarshalText(text []byte) error

type InvertedSignature

type InvertedSignature [65]byte

InvertedSignature represents a standard Signature but the order of component `V` is inverted, being the last byte of the bytes (where it's the first byte in the standard `btcec` Signature).

The InverteSignature is in packed form of 65 bytes and order of the components is R (32 bytes) + S (32 bytes) + V (1 byte).

The components can be retrieved with `R()`, `S()` and `V()`.

This form is used on certain Ethereum construct like when doing a personal signing where the `V` component must be the last component of the signature for correct recovery.

func NewInvertedSignatureFromBytes

func NewInvertedSignatureFromBytes(in []byte) (out InvertedSignature, err error)

func (InvertedSignature) R

func (s InvertedSignature) R() *big.Int

R returns the R component of signature.

func (InvertedSignature) Recover

func (s InvertedSignature) Recover(messageHash Hash) (Address, error)

RecoverPersonal is a shortcut method for `signature.ToSignature().Recover(messageHash)`.

func (InvertedSignature) RecoverPersonal

func (s InvertedSignature) RecoverPersonal(signingData Hex) (Address, error)

RecoverPersonal is a shortcut method for `signature.ToSignature().RecoverPersonal(signingData)`.

func (InvertedSignature) S

func (s InvertedSignature) S() *big.Int

S returns the R component of signature.

func (InvertedSignature) String

func (s InvertedSignature) String() string

func (InvertedSignature) ToSignature

func (s InvertedSignature) ToSignature() (out Signature)

func (InvertedSignature) V

func (s InvertedSignature) V() byte

V returns the recovery ID according to Bitcoin rules for the signature recovery. Ethereum augmented recovery ID to protect agaisnt replay attacks is **not** applied here.

See https://bitcoin.stackexchange.com/a/38909 for extra details

type KeyBag

type KeyBag struct {
	Keys []*PrivateKey `json:"keys"`
}

KeyBag holds private keys in memory, for signing transactions.

func NewKeyBag

func NewKeyBag() *KeyBag

type Log

type Log struct {
	Address     []byte   `json:"address,omitempty"`
	Topics      [][]byte `json:"topics,omitempty"`
	Data        []byte   `json:"data,omitempty"`
	IsAnonymous bool     `json:"anonymous,omitempty"`

	// supplement
	Index      uint32 `json:"index,omitempty"`
	BlockIndex uint32 `json:"blockIndex,omitempty"`
}

type LogDecoder

type LogDecoder struct {
	DataDecoder *Decoder
	// contains filtered or unexported fields
}

func NewLogDecoder

func NewLogDecoder(logEvent *Log) *LogDecoder

func (*LogDecoder) ReadData

func (d *LogDecoder) ReadData(typeName string) (out interface{}, err error)

func (*LogDecoder) ReadTopic

func (d *LogDecoder) ReadTopic() ([]byte, error)

func (*LogDecoder) ReadTypedTopic

func (d *LogDecoder) ReadTypedTopic(typeName string) (out interface{}, err error)

type LogEvent

type LogEvent struct {
	Def  *LogEventDef
	Data []interface{}
	// contains filtered or unexported fields
}

func (*LogEvent) AppendArgFromString

func (f *LogEvent) AppendArgFromString(v string)

func (*LogEvent) Encode

func (f *LogEvent) Encode() (topics []Topic, data []byte, err error)

func (*LogEvent) MustEncode

func (f *LogEvent) MustEncode() (topics []Topic, data []byte)

type LogEventDef

type LogEventDef struct {
	Name       string
	Parameters []*LogParameter
}

func (*LogEventDef) LogID

func (l *LogEventDef) LogID() []byte

func (*LogEventDef) NewEvent

func (f *LogEventDef) NewEvent(args ...interface{}) *LogEvent

returned instantiate a new event from the log definition and uses the received arguments as elements used to resolve the parameters values (indexed and non-indexed).

A call is a particular instance of a Method where ultimately the parameters's value will be resolved. A method call in opposition to a method definition can be encoded according to Ethereum rules or decode data returned for this call against the definition.

func (*LogEventDef) NewEventFromString

func (f *LogEventDef) NewEventFromString(args ...string) *LogEvent

NewCallFromString works exactly like `NewCall“ except that it actually assumes all arguments are string version of the actual Ethereum types defined by the method and append them to the Data slice by calling `AppendArgFromString` which converts the string representation to the correct type.

func (*LogEventDef) Signature

func (l *LogEventDef) Signature() string

func (*LogEventDef) String

func (l *LogEventDef) String() string

type LogParameter

type LogParameter struct {
	Name     string
	TypeName string
	Type     SolidityType
	Indexed  bool

	// Components represents that struct fields of a particular tuple. Only
	// filled up when `TypeName` is equal to `tuple` (or array of tuples).
	//
	// TODO: This is a blind copy from Method as I think the same concept applies
	// to event, needs to validate using a test in `eth-go`.
	Components []*StructComponent
}

func (*LogParameter) GetName

func (p *LogParameter) GetName(index int) string

type MethodCall

type MethodCall struct {
	MethodDef *MethodDef
	Data      []interface{}
	// contains filtered or unexported fields
}

func (*MethodCall) AppendArg

func (f *MethodCall) AppendArg(v interface{})

func (*MethodCall) AppendArgFromString

func (f *MethodCall) AppendArgFromString(v string)

func (*MethodCall) Encode

func (f *MethodCall) Encode() ([]byte, error)

func (*MethodCall) MarshalJSONRPC

func (f *MethodCall) MarshalJSONRPC() ([]byte, error)

func (*MethodCall) MustEncode

func (f *MethodCall) MustEncode() []byte

type MethodDef

type MethodDef struct {
	Name             string
	Parameters       []*MethodParameter
	ReturnParameters []*MethodParameter
	StateMutability  StateMutability
}

func MustNewMethodDef

func MustNewMethodDef(signature string) *MethodDef

func NewMethodDef

func NewMethodDef(signature string) (*MethodDef, error)

func (*MethodDef) DecodeOutput

func (f *MethodDef) DecodeOutput(data []byte) ([]interface{}, error)

func (*MethodDef) DecodeOutputFromString

func (f *MethodDef) DecodeOutputFromString(data string) ([]interface{}, error)

func (*MethodDef) DecodeToObjectFromBytes

func (f *MethodDef) DecodeToObjectFromBytes(data []byte) (out map[string]interface{}, err error)

func (*MethodDef) DecodeToObjectFromDecoder

func (f *MethodDef) DecodeToObjectFromDecoder(decoder *Decoder) (out map[string]interface{}, err error)

func (*MethodDef) DecodeToObjectFromString

func (f *MethodDef) DecodeToObjectFromString(data string) (out map[string]interface{}, err error)

func (*MethodDef) MethodID

func (f *MethodDef) MethodID() []byte

func (*MethodDef) NewCall

func (f *MethodDef) NewCall(args ...interface{}) *MethodCall

NewCall instantiate a new call from the method definition and uses the received arguments as elements used to resolve the parameters values.

A call is a particular instance of a Method where ultimately the parameters's value will be resolved. A method call in opposition to a method definition can be encoded according to Ethereum rules or decode data returned for this call against the definition.

func (*MethodDef) NewCallFromString

func (f *MethodDef) NewCallFromString(args ...string) *MethodCall

NewCallFromString works exactly like `NewCall“ except that it actually assumes all arguments are string version of the actual Ethereum types defined by the method and append them to the Data slice by calling `AppendArgFromString` which converts the string representation to the correct type.

func (*MethodDef) Signature

func (f *MethodDef) Signature() string

func (*MethodDef) String

func (f *MethodDef) String() string

type MethodParameter

type MethodParameter struct {
	// Name represents the name of the parameter as defined by the
	// developer in the Solidity code of the contract.
	Name string
	// TypeName represents the type of the parameter, this is standard
	// types known to Solidity. Array have a suffix `[]` (can be nested)
	// and struct type is always `tuple` with an filled up `Components`
	// defining the struct.
	TypeName string
	// Type represents the parsed type of this parameter.
	Type SolidityType
	// TypeMutability is unclear, requires more investigation, I don't recall
	// to which Solidity concept it refers to.
	TypeMutability string
	// Payable determines if the parameter is a payable value so an
	// Ether value.
	Payable bool
	// InternalType is the internal type to the contract, usually equal
	// to `TypeName` but can be different for example if a type `uint`
	// was defined, in this case `TypeName` will be `uint256` and internal
	// type will be `uint`. Tuple which have `TypeName` `tuple` but internal
	// type is `struct <Contract>.<Struct>` is another exceptions.
	InternalType string
	// Components represents that struct fields of a particular tuple. Only
	// filled up when `TypeName` is equal to `tuple` (or array of tuples).
	Components []*StructComponent
}

func (*MethodParameter) Signature

func (p *MethodParameter) Signature() string

type PrivateKey

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

func NewPrivateKey

func NewPrivateKey(rawPrivateKey string) (*PrivateKey, error)

func NewRandomPrivateKey

func NewRandomPrivateKey() (*PrivateKey, error)

func (*PrivateKey) Bytes

func (p *PrivateKey) Bytes() (out []byte)

func (*PrivateKey) MarshalJSON

func (p *PrivateKey) MarshalJSON() ([]byte, error)

func (*PrivateKey) PublicKey

func (p *PrivateKey) PublicKey() *PublicKey

func (*PrivateKey) Sign

func (p *PrivateKey) Sign(messageHash Hash) (out Signature, err error)

Sign generates the signature for the according message hash based on this private key using ECDSA signature rules.

See Signature documentation for more info about return signature format.

func (*PrivateKey) SignPersonal

func (p *PrivateKey) SignPersonal(signingData Hex) (out Signature, err error)

SignPersonal computes the correct message from `signingData` according to [ERC-712](https://eips.ethereum.org/EIPS/eip-712) which is briefly `keccak256(bytesOf("\x19Ethereum Signed Message:\n") + bytesOf(toString(len(signingData))) + signingData)`.

This computed generated hash is then pass directly to `privateKey.Sign(personalMessageHash)`.

See Sign for more details.

func (*PrivateKey) String

func (p *PrivateKey) String() string

func (*PrivateKey) UnmarshalJSON

func (p *PrivateKey) UnmarshalJSON(v []byte) (err error)

type PublicKey

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

func NewPublicKeyFromECDSA

func NewPublicKeyFromECDSA(key *secp256k1.PublicKey) *PublicKey

func (PublicKey) Address

func (p PublicKey) Address() Address

type Signature

type Signature [65]byte

Signature represents a btcec Signature as computed from ecdsa.SignCompact(), this signature is in packed form of 65 bytes with ordered V (1 byte) + R (32 bytes) + S (32 bytes).

The components can be retrieved with `R()`, `S()` and `V()`.

func NewSignatureFromBytes

func NewSignatureFromBytes(in []byte) (out Signature, err error)

func (Signature) R

func (s Signature) R() *big.Int

func (Signature) Recover

func (s Signature) Recover(messageHash Hash) (Address, error)

func (Signature) RecoverPersonal

func (s Signature) RecoverPersonal(signingData Hex) (Address, error)

func (Signature) S

func (s Signature) S() *big.Int

func (Signature) String

func (s Signature) String() string

func (Signature) ToInverted

func (s Signature) ToInverted() (out InvertedSignature)

ToInverted returns the InvertedSignature version of this Signature, this is that the components are ordered as `R`, `S` then `V` in the inverted version.

This form is used on certain Ethereum construct like when doing a personal signing where the `V` component must be the last component of the signature for correct recovery.

func (Signature) V

func (s Signature) V() byte

V returns the recovery ID according to Bitcoin rules for the signature recovery. Ethereum augmented recovery ID to protect agaisnt replay attacks is **not** applied here.

See https://bitcoin.stackexchange.com/a/38909 for extra details

type SignedFixedPointType

type SignedFixedPointType struct {
	// BitsSize is the number of bites taken by this type, BitsSize / 8 = ByteSize, range of values is between 8 and 256 (inclusive) by step of 8
	BitsSize uint
	// ByteSize is the number of bytes taken by this type, ByteSize * 8 = BitsSize, range of values is between 1 and 32 (inclusive)
	ByteSize uint
	// Decimals represents the precision in decimals of this fixed type and will be between 0 and 80 (inclusive)
	Decimals uint
}

func (SignedFixedPointType) IsDynamic

func (t SignedFixedPointType) IsDynamic() bool

func (SignedFixedPointType) Kind

func (t SignedFixedPointType) Kind() TypeKind

func (SignedFixedPointType) Name

func (t SignedFixedPointType) Name() string

type SignedIntegerType

type SignedIntegerType struct {
	// BitsSize is the number of bites taken by this type, BitsSize / 8 = ByteSize, range of values is between 8 and 256 (inclusive) by step of 8
	BitsSize uint
	// ByteSize is the number of bytes taken by this type, ByteSize * 8 = BitsSize, range of values is between 1 and 32 (inclusive)
	ByteSize uint
}

func (SignedIntegerType) IsDynamic

func (t SignedIntegerType) IsDynamic() bool

func (SignedIntegerType) Kind

func (t SignedIntegerType) Kind() TypeKind

func (SignedIntegerType) Name

func (t SignedIntegerType) Name() string

type SolidityType

type SolidityType interface {
	Name() string
	Kind() TypeKind
	IsDynamic() bool
}

func ParseType

func ParseType(raw string) (SolidityType, error)

type StateMutability

type StateMutability int

ENUM(

Pure
View
NonPayable
Payable

)

const (
	// StateMutabilityPure is a StateMutability of type Pure.
	StateMutabilityPure StateMutability = iota
	// StateMutabilityView is a StateMutability of type View.
	StateMutabilityView
	// StateMutabilityNonPayable is a StateMutability of type NonPayable.
	StateMutabilityNonPayable
	// StateMutabilityPayable is a StateMutability of type Payable.
	StateMutabilityPayable
)

func ParseStateMutability

func ParseStateMutability(name string) (StateMutability, error)

ParseStateMutability attempts to convert a string to a StateMutability

func (StateMutability) MarshalText

func (x StateMutability) MarshalText() ([]byte, error)

MarshalText implements the text marshaller method

func (StateMutability) String

func (x StateMutability) String() string

String implements the Stringer interface.

func (*StateMutability) UnmarshalText

func (x *StateMutability) UnmarshalText(text []byte) error

UnmarshalText implements the text unmarshaller method

type StringArray

type StringArray []string

func (StringArray) At

func (a StringArray) At(index uint64, value interface{})

type StringType

type StringType struct {
}

func (StringType) IsDynamic

func (t StringType) IsDynamic() bool

func (StringType) Kind

func (t StringType) Kind() TypeKind

func (StringType) Name

func (t StringType) Name() string

type StructComponent

type StructComponent struct {
	InternalType string
	Name         string
	TypeName     string
	Type         SolidityType
}

func (*StructComponent) String

func (c *StructComponent) String() string

type StructType

type StructType struct {
}

func (StructType) IsDynamic

func (t StructType) IsDynamic() bool

func (StructType) Kind

func (t StructType) Kind() TypeKind

func (StructType) Name

func (t StructType) Name() string

type Timestamp

type Timestamp time.Time

Timestamp represents a timestamp value on the Ethereum chain always in UTC time zone. Recorded in unix seconds

func (Timestamp) MarshalJSONRPC

func (t Timestamp) MarshalJSONRPC() ([]byte, error)

func (Timestamp) MarshalText

func (t Timestamp) MarshalText() ([]byte, error)

func (*Timestamp) UnmarshalText

func (t *Timestamp) UnmarshalText(text []byte) error

type Token

type Token struct {
	Name        string   `json:"name"`
	Symbol      string   `json:"symbol"`
	Address     Address  `json:"address"`
	Decimals    uint     `json:"decimals"`
	TotalSupply *big.Int `json:"total_supply"`
}

func (*Token) Amount

func (t *Token) Amount(value int64) TokenAmount

func (*Token) AmountBig

func (t *Token) AmountBig(value *big.Int) TokenAmount

func (*Token) ID

func (t *Token) ID() uint64

func (*Token) String

func (t *Token) String() string

type TokenAmount

type TokenAmount struct {
	Amount *big.Int
	Token  *Token
}

func (TokenAmount) Bytes

func (t TokenAmount) Bytes() []byte

func (TokenAmount) Format

func (t TokenAmount) Format(truncateDecimalCount uint) string

func (TokenAmount) String

func (t TokenAmount) String() string

type Topic

type Topic [32]byte

func LogTopic

func LogTopic(in interface{}) *Topic

func (Topic) MarshalJSONRPC

func (f Topic) MarshalJSONRPC() ([]byte, error)

type TransactionType

type TransactionType uint8

ENUM(

Legacy
AccessList
DynamicFee

)

const (
	// TxTypeLegacy is a TransactionType of type Legacy.
	TxTypeLegacy TransactionType = iota
	// TxTypeAccessList is a TransactionType of type AccessList.
	TxTypeAccessList
	// TxTypeDynamicFee is a TransactionType of type DynamicFee.
	TxTypeDynamicFee
)

func ParseTransactionType

func ParseTransactionType(name string) (TransactionType, error)

ParseTransactionType attempts to convert a string to a TransactionType

func (TransactionType) String

func (x TransactionType) String() string

String implements the Stringer interface.

func (*TransactionType) UnmarshalText

func (b *TransactionType) UnmarshalText(text []byte) error

type TypeKind

type TypeKind int

ENUM(

	Boolean
	Address
	SignedInteger
	UnsignedInteger
	SignedFixedPoint
	UsignedFixedPoint
	FixedSizeBytes
	Bytes
	String
 FixedSizeArray
 Array
Struct

Mappings )

const (
	// TypeBoolean is a TypeKind of type Boolean.
	TypeBoolean TypeKind = iota
	// TypeAddress is a TypeKind of type Address.
	TypeAddress
	// TypeSignedInteger is a TypeKind of type SignedInteger.
	TypeSignedInteger
	// TypeUnsignedInteger is a TypeKind of type UnsignedInteger.
	TypeUnsignedInteger
	// TypeSignedFixedPoint is a TypeKind of type SignedFixedPoint.
	TypeSignedFixedPoint
	// TypeUsignedFixedPoint is a TypeKind of type UsignedFixedPoint.
	TypeUsignedFixedPoint
	// TypeFixedSizeBytes is a TypeKind of type FixedSizeBytes.
	TypeFixedSizeBytes
	// TypeBytes is a TypeKind of type Bytes.
	TypeBytes
	// TypeString is a TypeKind of type String.
	TypeString
	// TypeFixedSizeArray is a TypeKind of type FixedSizeArray.
	TypeFixedSizeArray
	// TypeArray is a TypeKind of type Array.
	TypeArray
	// TypeStruct is a TypeKind of type Struct.
	TypeStruct
	// TypeMappings is a TypeKind of type Mappings.
	TypeMappings
)

func ParseTypeKind

func ParseTypeKind(name string) (TypeKind, error)

ParseTypeKind attempts to convert a string to a TypeKind

func (TypeKind) String

func (x TypeKind) String() string

String implements the Stringer interface.

type Uint16

type Uint16 uint16

func (*Uint16) UnmarshalText

func (b *Uint16) UnmarshalText(text []byte) error

type Uint16Array

type Uint16Array []uint16

func (Uint16Array) At

func (a Uint16Array) At(index uint64, value interface{})

type Uint256

type Uint256 uint256.Int

func (*Uint256) MarshalJSONRPC

func (b *Uint256) MarshalJSONRPC() ([]byte, error)

func (*Uint256) MarshalText

func (b *Uint256) MarshalText() ([]byte, error)

func (*Uint256) UnmarshalText

func (b *Uint256) UnmarshalText(text []byte) error

type Uint32

type Uint32 uint32

func (*Uint32) UnmarshalText

func (b *Uint32) UnmarshalText(text []byte) error

type Uint32Array

type Uint32Array []uint32

func (Uint32Array) At

func (a Uint32Array) At(index uint64, value interface{})

type Uint64

type Uint64 uint64

func (*Uint64) UnmarshalText

func (b *Uint64) UnmarshalText(text []byte) error

type Uint64Array

type Uint64Array []uint64

func (Uint64Array) At

func (a Uint64Array) At(index uint64, value interface{})

type Uint8

type Uint8 uint8

func (*Uint8) UnmarshalText

func (b *Uint8) UnmarshalText(text []byte) error

type Uint8Array

type Uint8Array []uint8

func (Uint8Array) At

func (a Uint8Array) At(index uint64, value interface{})

type UnsignedFixedPointType

type UnsignedFixedPointType struct {
	// BitsSize is the number of bites taken by this type, BitsSize / 8 = ByteSize, range of values is between 8 and 256 (inclusive) by step of 8
	BitsSize uint
	// ByteSize is the number of bytes taken by this type, ByteSize * 8 = BitsSize, range of values is between 1 and 32 (inclusive)
	ByteSize uint
	// Decimals represents the precision in decimals of this fixed type and will be between 0 and 80 (inclusive)
	Decimals uint
}

func (UnsignedFixedPointType) IsDynamic

func (t UnsignedFixedPointType) IsDynamic() bool

func (UnsignedFixedPointType) Kind

func (UnsignedFixedPointType) Name

func (t UnsignedFixedPointType) Name() string

type UnsignedIntegerType

type UnsignedIntegerType struct {
	// BitsSize is the number of bites taken by this type, BitsSize / 8 = ByteSize, range of values is between 8 and 256 (inclusive) by step of 8
	BitsSize uint
	// ByteSize is the number of bytes taken by this type, ByteSize * 8 = BitsSize, range of values is between 1 and 32 (inclusive)
	ByteSize uint
}

func (UnsignedIntegerType) IsDynamic

func (t UnsignedIntegerType) IsDynamic() bool

func (UnsignedIntegerType) Kind

func (t UnsignedIntegerType) Kind() TypeKind

func (UnsignedIntegerType) Name

func (t UnsignedIntegerType) Name() string

Directories

Path Synopsis
Package json implements encoding and decoding of JSON as defined in RFC 7159.
Package json implements encoding and decoding of JSON as defined in RFC 7159.

Jump to

Keyboard shortcuts

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