使用PHP生成TRX地址
首先,使用PHP生成TRX地址需要你引入第三方的composer包,composer.json配置如下
{
"require": {
"bitwasp/bitcoin": "^1.0",
"iexbase/tron-api": "^4.0",
"bitwasp/buffertools": "^0.5.7",
"stephenhill/base58": "^1.1",
"kornrunner/keccak": "^1.1",
"web3p/web3.php": "^0.3.2",
"elliptic/elliptic-sdk": "^0.8.0",
"ramsey/uuid": "^3.9"
}
}然后运行命令composer install安装composer依赖包。
创建一个trx.php文件,代码如下:
<?php
require 'vendor/autoload.php';
use BitWasp\Bitcoin\Crypto\Random\Random;
use BitWasp\Bitcoin\Key\Factory\PrivateKeyFactory;
use BitWasp\Bitcoin\Bitcoin;
use IEXBase\TronAPI\Tron;
use StephenHill\Base58;
use kornrunner\Keccak;
class TRX {
public function generateWallet() {
try {
$tron = new Tron();
$newWallet = $tron->createAccount();
$addressBase58 = $newWallet->getAddress(true);
$privateKeyHex = $newWallet->getPrivateKey();
$publicKeyHex = $newWallet->getPublicKey();
} catch (Exception $e) {
echo "发生错误: " . $e->getMessage();
}
echo '钱包地址:' . $addressBase58 . '<br>';
echo '公钥:' . $publicKeyHex . '<br>';
echo '私钥:' . $privateKeyHex . '<br>';
}
}
$trx = new TRX();
//循环生成100个钱包
for ($i = 0; $i < 100; $i++) {
$trx->generateWallet();
echo '<hr />'
}访问这个trx.php文件,就可以一次性生成100个钱包了。