Blockchain-Ethereum-Transaction

 view release on metacpan or  search on metacpan

bin/ethereum-raw-tx  view on Meta::CPAN

#!/usr/bin/env perl
# PODNAME: ethereum-raw-tx
# ABSTRACT: Command line raw transaction creation and signing

our $AUTHORITY = 'cpan:REFECO';    # AUTHORITY
our $VERSION   = '0.009';          # VERSION

use strict;
use warnings;

use Carp;
use Getopt::Long;
use Pod::Usage;

use Blockchain::Ethereum::Transaction::Legacy;
use Blockchain::Ethereum::Transaction::EIP1559;
use Blockchain::Ethereum::Keystore::Key;

my ($tx_type, $chain_id, $nonce, $max_fee_per_gas, $max_priority_fee_per_gas, $gas_price, $gas_limit, $to, $value, $data, $private_key);
GetOptions(
    "tx-type=s"                => \$tx_type,
    "chain-id=s"               => \$chain_id,
    "nonce=s"                  => \$nonce,
    "max-fee-per-gas=s"        => \$max_fee_per_gas,
    "max-priority-fee-per-gas" => \$max_priority_fee_per_gas,
    "gas-price=s"              => \$gas_price,
    "gas-limit=s"              => \$gas_limit,
    "to=s"                     => \$to,
    "value=s"                  => \$value,
    "data=s"                   => \$data,
    "pk=s"                     => \$private_key
);

my %transaction_versions = (
    legacy  => "Blockchain::Ethereum::Transaction::Legacy",
    eip1559 => "Blockchain::Ethereum::Transaction::EIP1519",
);

pod2usage(1) unless $tx_type && $transaction_versions{$tx_type} && $nonce && $gas_limit;

my %params = (
    chain_id  => $chain_id,
    nonce     => $nonce,
    gas_limit => $gas_limit,
    to        => $to,
    value     => $value,
    data      => $data,
);

if ($tx_type eq 'eip1559') {
    $params{max_fee_per_gas}          = $max_fee_per_gas;
    $params{max_priority_fee_per_gas} = $max_priority_fee_per_gas;
} else {
    $params{gas_price} = $gas_price;
}

my $tx = $transaction_versions{$tx_type}->new(%params);

$private_key =~ s/^0x//g;

my $key = Blockchain::Ethereum::Keystore::Key->new(
    private_key => pack "H*",
    $private_key
);

$key->sign_transaction($tx);

printf("%s\n", unpack("H*", $tx->serialize));

__END__

=pod

=encoding UTF-8

=head1 NAME

ethereum-raw-tx - Command line raw transaction creation and signing

=head1 VERSION

version 0.009

=head1 SYNOPSIS

ethereum-raw-tx [options]

Options:

    --txtype=legacy/eip1559 (Required)
    --chain-id (Required, if not give default is 1)
    --nonce (Required)
    --max-fee-per-gas (Required for eip1559 transactions)
    --max-priority-fee-per-gas (Required for eip1559 transactions)
    --gas-price (Required for legacy transactions)
    --gas-limit (Required)
    --to (Optional, for contract deployment transactions)
    --value (Optional)
    --data (Optional)

Example:

    ethereum-raw-tx --tx-type=legacy --chain-id=0x1 --nonce=0x9 --gas-price=0x4A817C800 --gas-limit=0x5208 --to=0x3535353535353535353535353535353535353535 --value=0xDE0B6B3A7640000 --pk=0x46464646464646464646464646464646464646464646464646464646464646...

=head1 DESCRIPTION

Standalone version for decoding and encoding RLP

=head1 AUTHOR

Reginaldo Costa <refeco@cpan.org>

=head1 COPYRIGHT AND LICENSE

This software is Copyright (c) 2023 by REFECO.

This is free software, licensed under:

  The MIT (X11) License

=cut

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 0.589 second using v1.00-cache-2.02-grep-82fe00e-cpan-2cc899e4a130 )