Rand Stats

Net::Ethereum

zef:knarkhov

Raku interface for Ethereum blockchain

A Raku interface for interacting with the Ethereum blockchain and ecosystem via JSON RPC API.

Synopsys

Quick start: compile and deploy new contract

#!/usr/bin/env raku

use Net::Ethereum;

my $ne = Net::Ethereum.new(
    :api_url('http://127.0.0.1:8501'),
    :show_progress(True),
    :unlockpwd('ospasswd'),
);

my %h = $ne.compile_and_deploy_contract(
    :contract_path('./sample.sol'),
    :compile_output_path('./compile'),  # will be created automatically if it does not exist
);
%h.gist.say;

Net::Ethereum class attributes

Fee and gas handling

Net::Ethereum derives fee data from the node and falls back gracefully on older or partially featured nodes:

See get_fee_data and get_base_fee_per_blob_gas in lib/Net/Ethereum.rakumod for details.

HTTP transport

All JSON-RPC calls in Net::Ethereum go through a small HTTP client abstraction (Net::Ethereum::HTTP::Client):

In normal usage you do not need to configure this explicitly; Net::Ethereum.new constructs a suitable HTTP client for you.

Dependencies and compatibility

This module is tested primarily against a Rakudo 6.d toolchain with the following Raku dependencies (declared in META6.json):

A typical local setup is:

zef install .  # installs Net::Ethereum along with the dependencies above

You can also use a containerized environment (e.g. Docker) that:

Refer to CI configuration (e.g. .gitlab-ci.yml) for an example of such an environment.

API documentation

This module was ported from Perl5 Net::Ethereum with core refactoring and breaking changes. Original Perl5 documentation could be incompatible with Raku Net::Ethereum, so feel free to report issues.

Known API differences

In Perl5 Net::Ethereum there are wait_for_contract and wait_for_transaction subroutines. Quick look for source code shows that this functions are very similar. In Raku Net::Ethereum we have one common method wait_for_transaction().

method wait_for_transaction( :@hashes!, Int :$iters?, Bool :$contract? ) returns Array { ... }

Method arguments are:

By default, the effective maximum wait time is:

Running tests from test-bundle

Tests from test-bundle are rather adjustable and full function testing is available if:

If your node running on different port, use helper-script hooks/forward.sh for quick forwarding:

./hooks/forward.sh 8501 <your_actual_node_port>

Environment

You should set contract transaction hash at global env variable TXHASH:

export TXHASH=0x244409bb2cced62a2b93b2688167438ef47f60f1b5aa8b6c64e9de460ddec604

Run tests

Test could be ran with prove or prove6:

prove6 ./t
prove -ve 'raku -Ilib'

Author

Please contact me via Matrix or LinkedIn. Your feedback is welcome at narkhov.pro.

Perl5 Net::Ethereum

CPAN

METACPAN

Habrahabr

Author

Contrubutor