NAME

Blockchain::Ethereum::ABI::Encoder - Contract ABI argument encoder

SYNOPSIS

Allows you to encode contract ABI arguments

my $encoder = Blockchain::Ethereum::ABI::Encoder->new();
$encoder->function('test')
    # string
    ->append(string => 'Hello, World!')
    # bytes
    ->append(bytes => unpack("H*", 'Hello, World!'))
    # tuple
    ->append('(uint256,address)' => [75000000000000, '0x0000000000000000000000000000000000000000'])
    # arrays
    ->append('bool[]', [1, 0, 1, 0])
    # multidimensional arrays
    ->append('uint256[][][2]', [[[1]], [[2]]])
    # tuples arrays and tuples inside tuples
    ->append('((int256)[2])' => [[[1], [2]]])->encode();
...

METHODS

append

Appends type signature and the respective values to the encoder.

Usage:

append(signature => value) -> L<Blockchain::Ethereum::ABI::Encoder>
  • %param key is the respective type signature followed by the value e.g. uint256 => 10

Returns $self

function

Appends the function name to the encoder, this is optional for when you want the function signature added to the encoded string or only the function name encoded.

Usage:

function(string) -> L<Blockchain::Ethereum::ABI::Encoder>
  • $function_name solidity function name e.g. for `transfer(address,uint256)` will be `transfer`

Returns $self

generate_function_signature

Based on the given function name and type signatures create the complete function signature.

Usage:

generate_function_signature() -> string

Returns the function signature string

encode_function_signature

Encode function signature keccak_256/sha3

Usage:

encode_function_signature('transfer(address,uint)') -> encoded string
  • $signature (Optional) function signature, if not given, will try to use the appended function name

Returns the encoded string 0x prefixed

encode

Encodes appended signatures and the function name (when given)

Usage:

encode() -> encoded string

Returns the encoded string, if function name was given will be 0x prefixed

AUTHOR

Reginaldo Costa, <refeco at cpan.org>

BUGS

Please report any bugs or feature requests to https://github.com/refeco/perl-ABI

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc Blockchain::Ethereum::ABI::Encoder

LICENSE AND COPYRIGHT

This software is Copyright (c) 2022 by REFECO.

This is free software, licensed under:

The MIT License