I am trying to create a USDT transaction and I am having hardness to sign the transaction after creating it because the GetTransactionSign method is deprecated.
They advice to do it offline but I don’t know and I couldn’t find an explanation on docs. Can you show me a code example of how to do it?
This is how I created the transaction:
public function createTransaction() {
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.trongrid.io/wallet/createtransaction",
OTHER_OPTIONS,
CURLOPT_POSTFIELDS => json_encode([
'owner_address' => 'OWNER_ADDRESS',
'to_address' => 'TO_ADDRESS',
'amount' => 1,
'privateKey' => 'MY_PRIVATE_KEY',
'visible' => true
]),
CURLOPT_HTTPHEADER => [
"accept: application/json",
"content-type: application/json"
],
]);
$transaction = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $transaction;
}
}
Transaction signature generating process (from docs)
- Calculate the hash of the transaction.
- Sign the transaction hash with the sender’s private key.
- Add the generated signature to the transaction instance.
2
Answers
Signing the transaction requires the use of the private key. They don’t want you calling an external API to do this because private keys are meant to be private. This is what is meant by "doing it offline", as in do it in your own code so that you remain the only person with access to the private key.
You may want to take a look at the iexbase/tron-api package. It is a PHP based implementation of the Tron API. Even if you don’t use that package, you can dig through the code and see how they handle the signing.
You can start here which is the function that creates a transaction, signs it, and then sends it.
Please can you share how you used the package to solve the issue as am having same problems