分享最近开发的以太方套件 ethereum-tx
分享链接:https://github.com/web3p/ethereum-tx
先前练习写了 web3.php
这次练习写交易的函示库
各位可以使用 ethereum-tx 制作和签章一个以太坊交易
下面稍微介绍怎么签章交易
一般的交易:
use Web3p\EthereumTx\Transaction;
$transaction = new Transaction([
'nonce' => '0x01',
'from' => '0x0000000000000000000000000000000000000000',
'to' => ''0x0000000000000000000000000000000000000000',
'gas' => '0x76c0',
'gasPrice' => '0x9184e72a000',
'value' => '0x9184e72a',
'chainId' => 1,
'data' => ''
]);
合约交易:
use Web3p\EthereumTx\Transaction;
$transaction = new Transaction([
'nonce' => '0x01',
'from' => '0x0000000000000000000000000000000000000000',
'to' => ''0x0000000000000000000000000000000000000000', // contract address
'gas' => '0x76c0',
'gasPrice' => '0x9184e72a000',
'value' => '0x9184e72a',
'chainId' => 1,
'data' => 'contract function data you want to send'
]);
签章:
$signedTransaction = $transaction->sign('your private key');
程式码还有很多地方可以改进,也希望各位大神能提供意见
谢谢!