Fenguoz / tron-php

Support TRON's TRX and TRC20, which include functions such as address creation, balance query, transaction transfer, query the latest blockchain, query information based on the blockchain, and query information based on the transaction hash
MIT License
200 stars 72 forks source link

请问正式环境如何设定API KEY #10

Closed fbiceo closed 5 months ago

fbiceo commented 3 years ago

大大, 我使用 https://api.trongrid.io 正式环境上线测试 我没有设定trongrid申请的API KEY,因为我不知道要去哪里设定 但是我尝试发送几笔交易都可以正常且在tronscan.io查询到交易内容 现在我很纳闷为什么我没有设定trongrid的API KEY却可以正常进行交易(TRX币) 请问是每天有免费额度可以发送吗? 还是我要如何设定API KEY? 麻烦有空指导,谢谢

LBC100 commented 3 years ago

我也有此疑问

mandiuk commented 3 years ago

Oh actually its pretty simple.. based on code from manual it would be something like this:

use GuzzleHttp\Client;

$uri = 'https://api.trongrid.io';// mainnet
// $uri = 'https://api.shasta.trongrid.io';// shasta testnet
$api = new \Tron\Api(new Client(['base_uri' => $uri,'headers'=>['TRON-PRO-API-KEY'=>'YOUR API KEY']));

$trxWallet = new \Tron\TRX($api);
$addressData = $trxWallet->generateAddress();
// $addressData->privateKey
// $addressData->address

$config = [
    'contract_address' => 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t',// USDT TRC20
    'decimals' => 6,
];
$trc20Wallet = new \Tron\TRC20($api, $this->config);
$addressData = $trc20Wallet->generateAddress();