引入开发包
composer require myxtype/ethereum-client:dev-master
use xtype\Ethereum\Client as EthereumClient;
use xtype\Ethereum\Utils;
public function index(){
$Client = "https://bsc-dataseed.binance.org/"; // RPC网络地址
$PrivateKey = ""; // 私钥
$FromAddress = "0xd12f818423800dd535A7bfef1a4F7458Eb3d77fb"; //发送地址
$ToAddress = "0x42Fa428cD73e53EEEaaEc8C04B390690C5073d75"; //接收地址
$money = "0.01";
$client = new EthereumClient($Client);
$client->addPrivateKeys([$PrivateKey]);
$trans = [
"from" => $FromAddress,
"to" => $ToAddress,
"value" => Utils::ethToWei($money, true),
"data" => '0x',
];
$trans['gas'] = dechex(hexdec($client->eth_estimateGas($trans)) * 1.5);
$trans['gasPrice'] = $client->eth_gasPrice();
$trans['nonce'] = $client->eth_getTransactionCount('0xd12f818423800dd535A7bfef1a4F7458Eb3d77fb', 'pending');
$txid = $client->sendTransaction($trans);
print_r($txid);
}