Guides

Signing Guide โ€” Sign Tron Transactions Locally (Examples)

Tronfuel builds transactions for you. To broadcast them manually or via API, you must sign them using your private key.

#๐Ÿงพ Input Required

  • A raw Tron transaction JSON (as built via Tronfuel)
  • Your private key (hex format, never share it publicly)

#๐Ÿ“ฆ Install Dependencies

Ensure you have the required libraries installed for your language.

#๐ŸŸจ JavaScript / Node.js

Install:

 1npm install tronweb

Sign Transaction:

 1const TronWeb = require('tronweb');
 2const fs = require('fs');
 3
 4const privateKey = 'YOUR_PRIVATE_KEY_HEX';
 5const tronWeb = new TronWeb({
 6    fullHost: 'https://api.trongrid.io',
 7    privateKey
 8});
 9
10const tx = JSON.parse(fs.readFileSync('raw_tx.json', 'utf8'));
11
12tronWeb.trx.sign(tx, privateKey).then(signedTx => {
13    fs.writeFileSync('signed_tx.json', JSON.stringify(signedTx, null, 2));
14});

#๐Ÿ˜ PHP

Install via Composer:

 1composer require kornrunner/secp256k1
 2composer require kornrunner/keccak

Sign Transaction:

 1use kornrunner\Secp256k1;
 2use kornrunner\Keccak;
 3
 4$privateKey = 'YOUR_PRIVATE_KEY_HEX';
 5$transaction = json_decode(file_get_contents('raw_tx.json'), true);
 6
 7// Hash transaction
 8$txHash = hash('sha256', json_encode($transaction));
 9
10// Sign hash
11$secp = new Secp256k1();
12$signature = $secp->sign($txHash, $privateKey);
13
14// Add signature to transaction
15$transaction['signature'] = [bin2hex($signature->toDER())];
16
17file_put_contents('signed_tx.json', json_encode($transaction));

#๐Ÿ Python

Install via pip:

 1pip install tronpy

Sign Transaction:

 1from tronpy.keys import PrivateKey
 2import json
 3
 4priv_key = PrivateKey(bytes.fromhex("YOUR_PRIVATE_KEY_HEX"))
 5
 6with open("raw_tx.json") as f:
 7    tx = json.load(f)
 8
 9signed_tx = priv_key.sign_transaction(tx)
10
11with open("signed_tx.json", "w") as f:
12    json.dump(signed_tx, f)

#โ˜• Java

Install via Maven:

 1<dependency>
 2  <groupId>org.tron</groupId>
 3  <artifactId>tron-core</artifactId>
 4  <version>0.4.0</version>
 5</dependency>

Sign Transaction:

 1import org.tron.tronj.crypto.SECP256K1;
 2import org.tron.tronj.proto.Chain.Transaction;
 3import com.google.protobuf.util.JsonFormat;
 4
 5String privKey = "YOUR_PRIVATE_KEY_HEX";
 6
 7String rawJson = new String(Files.readAllBytes(Paths.get("raw_tx.json")));
 8Transaction.Builder txBuilder = Transaction.newBuilder();
 9JsonFormat.parser().merge(rawJson, txBuilder);
10
11SECP256K1.KeyPair kp = SECP256K1.KeyPair.create(SECP256K1.PrivateKey.fromHex(privKey));
12Transaction signedTx = WalletApi.signTransaction(txBuilder.build(), kp);
13
14Files.write(Paths.get("signed_tx.json"), JsonFormat.printer().print(signedTx).getBytes());