Net::Ethereum

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

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'),
);
%h.gist.say;

Net::Ethereum class attributes

  • api_url - URL of Ethereum node RPC server (http://127.0.0.1:8501 by default, public mutable);

  • abi - contents of .abi file generated by solidity compiler (public mutable);

  • contract_id - contract address (e.g. 0xb3abfa488058dba76206071b3600ae6e0dec3205, public mutable);

  • tx_wait_sec - method wait_for_transaction() by default is waiting transaction to be mined for 10 iterations, each iteration sleeps for $!tx_wait_sec seconds ([+ 5 +] by default).

  • keepalive - set to [+ True +] if your HTTP::UserAgent supports keep-alive connections ([- False -] by default);

  • solidity - path to solidity compiler (/usr/local/bin/solc by default);

  • conn_name - connection name in keep-alive mode: all keep-alive connections are storing with unique names ([+ parity-local +] by default);

  • debug - debugging flag ([- False -] by default);

  • return_raw_data - this flag enables including of raw data to Hash returned by unmarshal() method (it's useful while debugging);

  • show_progress - if this flag is set you will see textual progress bar while transaction acceptance waiting ([- False -] by default);

  • cleanup - this flag enables cleanup after compile_and_deploy_contract() method: unlink .abi and .bin files ([+ True +] by default);

  • unlockpwd - password for account unlocking, this attribute is immutable and could be set in constructor;

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:

  • @hashes - array of transaction hashes to be mined;

  • $iters - optional timeout iterations (one iteration takes 5 seconds).

  • $contract - optional boolean: True if we're waiting for contract deploy transaction, False for other transactions;

Running tests from test-bundle

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

  • ethereum node is running and available at http://127.0.0.1:8501;

  • solidity compiler is installed, working properly and available at /usr/local/bin/solc;

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

./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 LinkedIn or Twitter. Your feedback is welcome at narkhov.pro.

Perl5 Net::Ethereum

CPAN

METACPAN

Habrahabr

Author

Contrubutor

Net::Ethereum v0.0.168

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

Authors

  • Konstantin Narkhov

License

Artistic-2.0

Dependencies

Node::Ethereum::Keccak256::NativeJSON::FastHTTP::UserAgent:ver<1.1.57+>:auth<zef:knarkhov>HTTP::Request:ver<1.1.57+>:auth<zef:knarkhov>HTTP::Cookies:ver<1.1.57+>:auth<zef:knarkhov>Test::Mock

Test Dependencies

Provides

  • Net::Ethereum

Documentation

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.