Giter Club home page Giter Club logo

php-ethereum-offline-raw-tx's Introduction

php-ethereum-offline-tx Tests Coverage Status Latest Stable Version

Pure PHP Ethereum Offline Raw Transaction Signer

Ethereum raw transaction hash offline in PHP

Installation

$ composer require kornrunner/ethereum-offline-raw-tx

Usage

use kornrunner\Ethereum\Transaction;

$nonce    = '04';
$gasPrice = '03f5476a00';
$gasLimit = '027f4b';
$to       = '1a8c8adfbe1c59e8b58cc0d515f07b7225f51c72';
$value    = '2a45907d1bef7c00';

$privateKey = 'b2f2698dd7343fa5afc96626dee139cb92e58e5d04e855f4c712727bf198e898';

$transaction = new Transaction ($nonce, $gasPrice, $gasLimit, $to, $value);
$transaction->getRaw ($privateKey);
// f86d048503f5476a0083027f4b941a8c8adfbe1c59e8b58cc0d515f07b7225f51c72882a45907d1bef7c00801ba0e68be766b40702e6d9c419f53d5e053c937eda36f0e973074d174027439e2b5da0790df3e4d0294f92d69104454cd96005e21095efd5f2970c2829736ca39195d8

With different chainId

use kornrunner\Ethereum\Transaction;

$nonce    = '04';
$gasPrice = '03f5476a00';
$gasLimit = '027f4b';
$to       = '1a8c8adfbe1c59e8b58cc0d515f07b7225f51c72';
$value    = '2a45907d1bef7c00';
$chainId  = 1;

$privateKey = 'b2f2698dd7343fa5afc96626dee139cb92e58e5d04e855f4c712727bf198e898';

$transaction = new Transaction ($nonce, $gasPrice, $gasLimit, $to, $value);
$transaction->getRaw ($privateKey, $chainId);
// f86d048503f5476a0083027f4b941a8c8adfbe1c59e8b58cc0d515f07b7225f51c72882a45907d1bef7c008025a0db4efcc22a7d9b2cab180ce37f81959412594798cb9af7c419abb6323763cdd5a0631a0c47d27e5b6e3906a419de2d732e290b73ead4172d8598ce4799c13bda69

Create a EIP1559 transaction

use kornrunner\Ethereum\EIP1559Transaction;

$nonce = '02';
$maxPriorityFeePerGas = 'b2d05e00';
$maxFeePerGas = '6fc23ac00';
$gasLimit = '5208';
$to = '1a8c8adfbe1c59e8b58cc0d515f07b7225f51c72';
$value = '29a2241af62c0000';
$data = '';
$chainId = 1;

$privateKey = 'b2f2698dd7343fa5afc96626dee139cb92e58e5d04e855f4c712727bf198e898';

$transaction = new EIP1559Transaction($nonce, $maxPriorityFeePerGas, $maxFeePerGas, $gasLimit, $to, $value, $data);

$rawTx = $transaction->getRaw($privateKey, $chainId);
// 02f873010284b2d05e008506fc23ac00825208941a8c8adfbe1c59e8b58cc0d515f07b7225f51c728829a2241af62c000080c080a0dd32dc794af9a9085d6772c40656fc156a577570c6fd32f2a2d4126673373919a066cf1859672a9e6fdbb00ebd230bcfec66cac1c99f5c83598ecae6025d0e91f4

Crypto

Ethereum 0x9c7b7a00972121fb843af7af74526d7eb585b171

php-ethereum-offline-raw-tx's People

Contributors

diadal avatar first-wang avatar kornrunner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

php-ethereum-offline-raw-tx's Issues

Smart Contract to Wallet

Can I use that script to send a specific ERC20 token from a smart contract to a wallet? Thanks!

Error: invalid sender

I'm trying to send a transaction for signature, in response I get an error: Invalid sender

Example code

$nonce = '01';
$gasPrice = '03f5476a00';
$gasLimit = '027f4b';

    $transaction = new Web3Transaction(
        sprintf('0x%s', $nonce),
        sprintf('0x%s', $gasPrice),
        sprintf('0x%s', $gasLimit),
        '0x89ece67cad34d1c248fdd1d34a1008a3a67209bb',
        $dataUser->address,
        '1000000000000000000',
    );

    $signedTx = $transaction->getRaw($dataUser->private_key, 56);

    $web3->getEth()->sendRawTransaction(sprintf('0x%s', $signedTx), function ($err, $tx) use (&$result) {
        if ($err !== null) {
            throw new \Exception($err->getMessage());
        }

        $result = $tx;
    });

    dd($result);

Not working with chainId 56

Hello,

I am trying to generate a HEX using chain ID 56, and after the sign, when I decode it, seems that uses another "sender" than the one of the private key, when generating the transaction.
By using same private key and changing only amount: from 0.1 to 0.01, changes the sender.

Call to undefined function Mdanter error

When I use your code and execute it after chanding with my own values, I am receiving this error:
PHP Fatal error: Uncaught Error: Call to undefined function Mdanter\\Ecc\\Curves\\gmp_init() in /var/www/html/vendor/mdanter/ecc/src/Curves/SecgCurve.php:122

May you tell me pleae what is this problem for and how can I solve it? Maybe I had a mistake, or the code has a bug!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.