Reputation: 751
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}'
Upvotes: 1
Views: 4780
Reputation: 751
I figured it out, I was preparing the data wrong..
Instead creating an array -
$postData = [
'privateKey' => 'MY Private Key',
'toAddress' => 'To Address',
'amount' => '100000'
];
I needed to do the literal string and not encode it.
$postData = '{"privateKey": "xxx", "toAddress..etc
Just like in the example given in the sandbox.
Upvotes: 1