Documentation

ABIEncoder
in package

ABIEncoder handles the encoding and decoding of ABI data in Ethereum smart contracts.

Tags
author

DubbaThony

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
throws
EthBinderArgumentException

Thrown if validation of signature fails.

throws
EthBinderLogicException

Thrown if function name end is not found or if other logic error occurs.

throws
EthBinderRuntimeException

Thrown if decoder fails

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
throws
EthBinderLogicException

Thrown if function name end is not found or indicates other bug.

throws
EthBinderArgumentException

Thrown if validation of signature fails.

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
throws
EthBinderArgumentException

Thrown if provided tuple is invalid.

Return values
array<string|int, mixed>

An array of the constituent types.

validateSignature()

private static validateSignature(string $signature) : void
Parameters
$signature : string
Tags
throws
EthBinderArgumentException

thrown whenever validation fails


        
On this page

Search results