# Tron (TRX & TRC20)

## Sign Transaction

The D'CENT Web SDK provides functions for signing transaction of coins.

### **getTronSignedTransaction()**

#### Supported Coin Type

* TRON

#### Parameters&#x20;

* transactionJson: this value conforms JSON format of Transaction Types in [Tron Docs](https://github.com/tronscan/tronscan-node-client)

#### Requirements:

* `D'CENT Bridge` version 1.4.0 or higher is required.
* D'CENT Biometric Wallet version 2.3.0 or higher is required.

#### Useage&#x20;

```javascript
const decode58Check = require('@tronscan/client/src/utils/crypto').decode58Check
const { Transaction } = require('@tronscan/client/src/protocol/core/Tron_pb')
const googleProtobufAnyPb = require('google-protobuf/google/protobuf/any_pb.js')
const _buf2hex = (buffer) => { // buffer is an ArrayBuffer
    return Array.prototype.map.call(new Uint8Array(buffer), x => ('00' + x.toString(16)).slice(-2)).join('');
}
const baseURL = 'https://api.trongrid.io'
// get node info
const command = '/wallet/getnodeinfo'
const reponse = await axios.get(baseURL + command)
let dataInfo = response.data
let arrBlcokInfo = dataInfo.block.split(',')
const nodeInfo = {
    number: arrBlcokInfo[0].split(':')[1],
    hash: arrBlcokInfo[1].split(':')[1],
}

let transferContract = new TronscanSdk.TransferContract()
transferContract.setToAddress(Uint8Array.from(decode58Check(toAddr)))
transferContract.setOwnerAddress(Uint8Array.from(decode58Check(fromAddr)))
transferContract.setAmount(amount)

let anyValue = new googleProtobufAnyPb.Any();
anyValue.pack(transferContract.serializeBinary(), 'protocol.' + typeName)
let contract = new Transaction.Contract();
contract.setType(contractType)
contract.setParameter(anyValue)

const refBlockHash = Buffer.from(nodeInfo.hash, 'hex').slice(8, 16).toString('base64');
const blockNumber = Number(nodeInfo.number);
const refBlockBytes = getBlockBytes(blockNumber).toString('base64');

let raw = new Transaction.raw()

raw.addContract(contract);
raw.setRefBlockNum(blockNumber)
raw.setRefBlockBytes(refBlockBytes)
raw.setRefBlockHash(refBlockHash)
raw.setTimestamp(Date.now());
raw.setExpiration(Date.now() + (100 * 60 * 60 * 1000)) // 10 hours
if (contractType === Transaction.Contract.ContractType.TRIGGERSMARTCONTRACT) {
    raw.setFeeLimit(50 * 1000000) // transfer fee limit
}
let transaction = new Transaction();
transaction.setRawData(raw);

const unsignedTx = _buf2hex(raw.serializeBinary())

const transactionJson = {
    unsignedTx: unsignedTx,
    fee: fee
    path: `m/44'/195'/0'/0/0`,
}

var result
try {
    result = await DcentWebConnector.getTronSignedTransaction(transactionJson);    
} catch (e) {
    console.log(e)
    result = e
}
```

#### Returned response object

* The property of the response's parameter, the pubkey is deprecated.

```json
{
    "header": {
        "version": "1.0",
        "response_from": "tron",
        "status": "success"
    },
    "body": {
        "command": "transaction",
        "parameter": {
            "signed_tx": "0x35544659743d463715380a2f66205ac9c38feb04033c29a5d415f8b009f566664a1972ac8be256308ec9b38a726f02eec103fc74963d7caf783cd55f1d7610d900",
            "pubkey": "0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
        }
    }
}
```

### getTrcTokenSignedTransactio&#x6E;**()**

#### Supported Coin Type

* TRON\_TRC\_TOKEN

#### Parameters&#x20;

* Same as `getTronSignedTransaction()`&#x20;

#### Returned response object

* Same as `getTronSignedTransaction()`&#x20;


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dev-docs.dcentwallet.com/dcent-biometric-wallet-for-pc/dcent-web-connector/tron-trx-and-trc20.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
