NAME
Web3::Tiny - A small, dependency-light way to talk to Ethereum from Perl
SYNOPSIS
use Web3::Tiny;
use Web3::Tiny::Util qw(to_wei from_wei);
my $web3 = Web3::Tiny->new(rpc_url => 'https://ethereum-rpc.publicnode.com');
print $web3->block_number, "\n";
print from_wei($web3->get_balance('0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045')), " ETH\n";
# --- read from a contract ---
my $weth = $web3->contract(
address => '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
abi => {
symbol => { sig => 'symbol()', returns => ['string'] },
balanceOf => { sig => 'balanceOf(address)', returns => ['uint256'] },
},
);
print $weth->call('symbol'), "\n";
print $weth->call('balanceOf', '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045'), "\n";
# --- sign and send a transaction ---
my $wallet = $web3->wallet(private_key => '0x...');
my $erc20 = $web3->contract(
address => '0x...',
abi => { transfer => { sig => 'transfer(address,uint256)', returns => ['bool'] } },
);
my $tx_hash = $erc20->send($wallet, 'transfer', $to_address, to_wei('1.5'));
DESCRIPTION
Web3::Tiny is a minimal Ethereum toolkit: JSON-RPC transport, Solidity ABI encoding/decoding, secp256k1/Keccak256/RLP for signing legacy transactions, and thin wrappers for calling and sending to contracts.
Transport and encoding (HTTP::Tiny, JSON::PP, Math::BigInt) are Perl core. The cryptography -- secp256k1/ECDSA and Keccak-256 (see Web3::Tiny::Secp256k1 and Web3::Tiny::Keccak256) -- is a thin wrapper around CryptX, an XS module wrapping the well-audited libtomcrypt C library, rather than a hand-rolled implementation.
Scope
This is intentionally small. It supports:
The common Solidity ABI scalar types, plus
T[]/T[k]arrays of them (no tuples/structs, no arrays-of-arrays)Legacy (pre-EIP-1559) transactions with EIP-155 replay protection
EIP-55 checksummed addresses
It does not implement EIP-1559 transactions, event log filter/decoding helpers, or ENS resolution. Patches welcome.
SEE ALSO
Web3::Tiny::RPC, Web3::Tiny::ABI, Web3::Tiny::Wallet, Web3::Tiny::Contract, Web3::Tiny::Secp256k1, Web3::Tiny::Keccak256, Web3::Tiny::RLP, Web3::Tiny::Util
AUTHOR
Alex Pepper <axpepper@gmail.com>
LICENSE
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.