ABIEncoder
in package
ABIEncoder handles the encoding and decoding of ABI data in Ethereum smart contracts.
Tags
Table of Contents
Methods
- decode() : AbiTuple
- Decodes ABI data returned from an Ethereum smart contract function using function signature (which can have fictional function name, but that's optional)
- encode() : string
- Encodes ABI data for an Ethereum smart contract function. It returns binary blob which can be `bin2hex()`-ed for presentation purposes.
- explodeTuple() : array<string|int, mixed>
- Splits a tuple type into its constituent types, preserving child tuples as single type. Input must start with `(` and end with `)`, without function name etc. Example input and output: "(uint256,(uint8,uint16)[],bytes)" => ["uint256", "(uint8,uint16)[]", "bytes"]
- createEncodingFromType() : AbstractABIValue
- validateSignature() : void
Methods
decode()
Decodes ABI data returned from an Ethereum smart contract function using function signature (which can have fictional function name, but that's optional)
public
static decode(string $signature, string $dataBin) : AbiTuple
Parameters
- $signature : string
-
The function signature including the function name and its parameters.
- $dataBin : string
-
The ABI-encoded binary data.
Tags
Return values
AbiTuple —The decoded ABI data as an AbiTuple.
encode()
Encodes ABI data for an Ethereum smart contract function. It returns binary blob which can be `bin2hex()`-ed for presentation purposes.
public
static encode(string $signature, array<string|int, mixed> $data[, bool $withTransactionSignature = true ]) : string
Parameters
- $signature : string
-
The function signature including the function name and its parameters.
- $data : array<string|int, mixed>
-
The data to encode.
- $withTransactionSignature : bool = true
-
Whether to prepend the function selector hash to the encoded data.
Tags
Return values
string —The ABI-encoded binary blob.
explodeTuple()
Splits a tuple type into its constituent types, preserving child tuples as single type. Input must start with `(` and end with `)`, without function name etc. Example input and output: "(uint256,(uint8,uint16)[],bytes)" => ["uint256", "(uint8,uint16)[]", "bytes"]
public
static explodeTuple(string $types) : array<string|int, mixed>
Parameters
- $types : string
-
The tuple types string.
Tags
Return values
array<string|int, mixed> —An array of the constituent types.
createEncodingFromType()
private
static createEncodingFromType(string $type, mixed $data) : AbstractABIValue
Parameters
- $type : string
- $data : mixed
Tags
Return values
AbstractABIValuevalidateSignature()
private
static validateSignature(string $signature) : void
Parameters
- $signature : string