# Generating Signed Transaction
Install the npm library [here](🔗) or download the [utils](🔗) and the [lib](🔗) folders into your project to use natively.
Alternatively, you can use [API Signature and Broadcast Flow](🔗) to generate a signed transaction.
## Creating a Transaction
Import [transactionBuilder](🔗) and [crypto](🔗) into your JavaScript file.
This function from the imported transactionBuilder file will create the Transaction Object.
The parameters for this function are:
Value | Data Type | Description |
token | String | The asset you want to send in your transaction. Example: "TRX" |
from | String | The address that you want to send from in your transaction. Example: "TDCMWoSbAfcegQqNUaRNjGhY4tAbdCmdwi" |
to | String | The address that you want to send to in your transaction. Example: "TQ6pM81JDC2GhrUoNYtZGvPc7SvyqcemEu" |
amount | Integer | The amount you want to spend of the specified token. If you want to send "TRX", make sure you multiply this value by 1000000. Example: If you want to send 2 TRX, use 2000000 |
The buildTransferTransaction specified above will return the value of buildTransferContract, which is the function that creates the Transaction Object.
## Signing the Transaction
This function from the imported crypto file will sign the Transaction Object.
The parameters for this function are:
Value | Data Type | Description |
priKeyBytes | Byte Array. You can also use a String due the function converting the value to byte array if needed. | The private key of the account. |
Transaction | Transaction Object | The bundled transaction to be sent. |
After successfully running these functions, you will have a signed transaction that can be broadcasted to the TRON blockchain.
## Full Code Example
# Transaction Confirmation
The mechanism of TRON's block validation is that the current block is validated after the current block is produced and 19 different SRs produce subsequent blocks based on that block.
Whether a transaction is to be confirmed or not requires the block in which the transaction is to be confirmed. TRON provides the /walletsolidty/ interface to make it easier for users to search for confirmed transactions, the following describes how to confirm different types of transactions.
Transaction Type | Method of transaction confirmation |
transferContract and transferAssetContract | As long as the transaction can query the results via walletsolidity/gettransactioninfobyid or walletsolidity/gettransactionbyid. |
TriggerSmartContract | **There are two ways to judge:** 1. Find transactionInfo.receipt.result=success via the /walletsolidity/gettransactioninfobyid interface (It is not recommended to use transactionInfo.result to judge, because for the http interface, successful transactions do not return this field by default). 2. Via /walletsolidity/gettransactionbyid The interface found transaction.ret.contractRet =success |
InternalTransaction | Query by /walletsolidity/gettransactioninfobyid. Http interface: For successful transactions, the rejected field is not returned by default. For failed transactions, rejected=true. Grpc interface: For successful transactions, rejected=false (indicating that the current internalTransaction has not been discarded), For failed transactions, rejected=true. |