1

I am playing around with the TRON api and trying to send transactions using the PHP curl method. I can successfully send the transaction in the TRON Developer sandbox but get and error when executing it on my server.

Error im receiving -

status_code: 200
{"result": {"code": "CONTRACT_VALIDATE_ERROR","message": "313a39343a20494e56414c49442068657820537472696e67"}}

My php Curl request -

$ch = curl_init();
$headers  = [
        'Content-Type: application/json'
    ];
$postData = [
'privateKey' => 'MY Private Key',
'toAddress' => 'To Address',
'amount' => '100000'
];
curl_setopt($ch, CURLOPT_URL,"https://api.trongrid.io/wallet/easytransferbyprivate");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postData));           
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result     = curl_exec ($ch);
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

echo $statusCode;
print_r($result);

Here is the link to the TRON sandbox im using -

https://developers.tron.network/reference#east-transfer-by-private-key

The success code in the sandbox is 200 so not sure why im receiving that and I am not sure how to lookup the returned error message, any idea what im doing wrong?

This is the sample post request given from TRON -

curl -X POST  https://api.trongrid.io/wallet/easytransferbyprivate -d '{"privateKey": "D95611A9AF2A2A45359106222ED1AFED48853D9A44DEFF8DC7913F5CBA727366", "toAddress":"4112E621D5577311998708F4D7B9F71F86DAE138B5","amount":10000}'
4

1 回答 1

1

我想通了,我准备数据错误..

而是创建一个数组 -

$postData = [
    'privateKey' => 'MY Private Key',
    'toAddress' => 'To Address',
    'amount' => '100000'
];

我需要做文字字符串而不是对其进行编码。

$postData = '{"privateKey": "xxx", "toAddress..etc

就像沙盒中给出的示例一样。

于 2020-09-07T00:59:41.890 回答