Skip to content

Commit

Permalink
Adding Tron
Browse files Browse the repository at this point in the history
  • Loading branch information
productshiv committed Apr 6, 2024
1 parent c1e2276 commit 1bea23b
Show file tree
Hide file tree
Showing 92 changed files with 11,333 additions and 0 deletions.
8 changes: 8 additions & 0 deletions v1.0/RPC Nodes/rpc-others/rpc-tron.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: "Tron"
slug: "rpc-tron"
excerpt: ""
hidden: false
createdAt: "Wed Mar 06 2024 10:35:18 GMT+0000 (Coordinated Universal Time)"
updatedAt: "Wed Mar 06 2024 13:09:53 GMT+0000 (Coordinated Universal Time)"
---
202 changes: 202 additions & 0 deletions v1.0/RPC Nodes/rpc-others/rpc-tron/rpc-tron-accountpermissionupdate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
---
title: "accountpermissionupdate"
slug: "rpc-tron-accountpermissionupdate"
excerpt: "Tron RPC"
hidden: false
metadata:
description: "Tron RPC"
image: []
keywords: "tron, rpc"
robots: "index"
createdAt: "Wed Mar 06 2024 10:35:44 GMT+0000 (Coordinated Universal Time)"
updatedAt: "Sat Apr 06 2024 12:59:44 GMT+0000 (Coordinated Universal Time)"
---
[block:html]
{
"html": "<div style=\"padding: 10px 20px; border-radius: 5px; background-color: #e6e2ff; margin: 0 0 30px 0;\">\n <h5>Archive Method</h5>\n <p>Only on the full archive nodes. Complex queries might take longer and incur additional cost</p>\n</div>"
}
[/block]


### How to use it

{% code overflow="wrap" lineNumbers="true" %}

```typescript
// yarn add @tatumio/tatum

import { TatumSDK, Tron, Network, TronPermission, AccountPermissionUpdateOptions } from '@tatumio/tatum'

const tatum = await TatumSDK.init<Tron>({network: Network.TRON})

const owner: TronPermission = {
type: 0,
permissionName: "owner",
threshold: 1,
operations: "",
keys: [
{
address: "TZ4UXDV5ZhNW7fb2AMSbgfAEZ7hWsnYS2g",
weight: 1
}
]
}

const active: TronPermission = {
"type": 2,
"permission_name": "active0",
"threshold": 2,
"operations": "7fff1fc0037e0000000000000000000000000000000000000000000000000000",
"keys": [
{
"address": "TZ4UXDV5ZhNW7fb2AMSbgfAEZ7hWsnYS2g",
"weight": 1
},
{
"address": "TPswDDCAWhJAZGdHPidFg5nEf8TkNToDX1",
"weight": 1
}
]
}

const res = await tatum.rpc.accountPermissionUpdate('TZ4UXDV5ZhNW7fb2AMSbgfAEZ7hWsnYS2g', [active], owner, {
visible: true
})

await tatum.destroy() // Destroy Tatum SDK - needed for stopping background jobs
```

{% endcode %}

### Overview

The `accountPermissionUpdate` method is used to update an account's permissions on the TRON network. These permissions include the owner permission, account witness permissions, and a list of active permissions. The response is an unsigned transaction, with the transaction type being `AccountPermissionUpdateContract`.

### Parameters

- `ownerAddress` (string): The address of the owner.
- `actives` (TronPermission\[]): An array of active permissions for the account.
- `owner` (TronPermission): The owner permission for the account.
- `options` (object, optional): This optional parameter contains the following properties:
- `visible` (boolean, optional): Optional parameter to specify whether the address is in base58 format.

Each `TronPermission` object has the following properties:

- `type` (number): The permission type.
- `permissionName` (string): The permission name.
- `threshold` (number): The threshold.
- `operations` (string): The operations the permission has.
- `keys` (Array\<{ address: string, weight: number }>): An array of objects that represent the addresses and their respective weights that jointly own the permission. Up to 5 keys are allowed.

### Return Object

- `raw_data.contract` - The main content of the transaction, contract is a list, but only one element is used at present. Different types of transactions have different contract contents. For example, for a TRX transfer type transaction, the contract will include the transfer amount, receiver address and other information. TRON supports multiple types of contracts, please refer to the official documentation [Types of Transaction](https://developers.tron.network/docs/tron-protocol-transaction#types-of-transaction).
- `raw_data.ref_block_bytes` - The height of the transaction reference block, using the 6th to 8th (exclusive) bytes of the reference block height, a total of 2 bytes. The reference block is used in the TRON TAPOS mechanism, which can prevent a replay of a transaction on forks that do not include the referenced block. Generally, the latest solidified block is used as the reference block.
- `raw_data.ref_block_hash` - The hash of the transaction reference block, using the 8th to 16th (exclusive) bytes of the reference block hash, a total of 8 bytes. The reference block is used in the TRON TAPOS mechanism, which can prevent a replay of a transaction on forks that do not include the referenced block. Generally, the latest solidified block is used as the reference block.
- `raw_data.expiration` - Transaction expiration time, beyond which the transaction will no longer be packed. If the transaction is created by calling the java-tron API, its expiration time will be automatically set by the node to the value of adding 60 seconds to the timestamp of the node's latest block. The expiration time interval can be modified in the node's configuration file, the maximum value cannot exceed 24 hours.
- `raw_data.data` - Transaction memo.
- `raw_data.timestamp` - Transaction timestamp, set as the transaction creation time.
- `raw_data.fee_limit` - The maximum energy cost allowed for the execution of smart contract transactions. Only deploying and triggering smart contract transactions need to be set, others not.
- `signature` - The sender's signature for the transaction. This proves that the transaction could only have come from the sender and was not sent fraudulently.
- `txID` - transaction id

Since the transaction type is `AccountPermissionUpdateContract`, the fields contained in `raw_data.contract[0].parameter.value` in the transaction are as follows:

- `owner_address` (string): The owner's account address.
- `owner` (Permission): The owner permission of the account.
- `witness` (Permission): Account witness permissions.
- `actives` (Permission\[]): List of active permissions for the account.

### HTTP Request Example

```json
{
"owner_address": "TZ4UXDV5ZhNW7fb2AMSbgfAEZ7hWsnYS2g",
"actives": [
{
"type": 2,
"permission_name": "active0",
"threshold": 2,
"operations": "7fff1fc0037e0000000000000000000000000000000000000000000000000000",
"keys": [
{
"address": "TZ4UXDV5ZhNW7fb2AMSbgfAEZ7hWsnYS2g",
"weight": 1
},
{
"address": "TPswDDCAWhJAZGdHPidFg5nEf8TkNToDX1",
"weight": 1
}
]
}
],
"owner": {
"type": 0,
"permission_name": "owner",
"threshold": 1,
"operations": "",
"keys": [
{
"address": "TZ4UXDV5ZhNW7fb2AMSbgfAEZ7hWsnYS2g",
"weight": 1
}
]
},
"visible": true
}
```

### HTTP Response Example

```json
{
"visible": true,
"txID": "f0fcda10229a8e289666c4d4c8756ad86e6df84966226bd9bc98e1607a4826b0",
"raw_data": {
"contract": [
{
"parameter": {
"value": {
"owner": {
"keys": [
{
"address": "TZ4UXDV5ZhNW7fb2AMSbgfAEZ7hWsnYS2g",
"weight": 1
}
],
"threshold": 1,
"permission_name": "owner"
},
"owner_address": "TZ4UXDV5ZhNW7fb2AMSbgfAEZ7hWsnYS2g",
"actives": [
{
"operations": "7fff1fc0037e0000000000000000000000000000000000000000000000000000",
"keys": [
{
"address": "TZ4UXDV5ZhNW7fb2AMSbgfAEZ7hWsnYS2g",
"weight": 1
},
{
"address": "TPswDDCAWhJAZGdHPidFg5nEf8TkNToDX1",
"weight": 1
}
],
"threshold": 2,
"type": "Active",
"permission_name": "active0"
}
]
},
"type_url": "type.googleapis.com/protocol.AccountPermissionUpdateContract"
},
"type": "AccountPermissionUpdateContract"
}
],
"ref_block_bytes": "aeab",
"ref_block_hash": "90861e40e6675e8e",
"expiration": 1684491273000,
"timestamp": 1684491216214
},
"raw_data_hex": "0a02aeab220890861e40e6675e8e40a886849c83315aea01082e12e5010a3c747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e4163636f756e745065726d697373696f6e557064617465436f6e747261637412a4010a1541fd49eda0f23ff7ec1d03b52c3a45991c24cd440e12241a056f776e657220013a190a1541fd49eda0f23ff7ec1d03b52c3a45991c24cd440e1001226508021a0761637469766530200232207fff1fc0037e00000000000000000000000000000000000000000000000000003a190a1541fd49eda0f23ff7ec1d03b52c3a45991c24cd440e10013a190a154198927ffb9f554dc4a453c64b2e553a02d6df514b100170d6ca809c8331"
}
```
91 changes: 91 additions & 0 deletions v1.0/RPC Nodes/rpc-others/rpc-tron/rpc-tron-broadcasthex.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
---
title: "broadcasthex"
slug: "rpc-tron-broadcasthex"
excerpt: "Tron RPC"
hidden: false
metadata:
description: "Tron RPC"
image: []
keywords: "tron, rpc"
robots: "index"
createdAt: "Wed Mar 06 2024 10:35:44 GMT+0000 (Coordinated Universal Time)"
updatedAt: "Sat Apr 06 2024 13:09:04 GMT+0000 (Coordinated Universal Time)"
---
[block:html]
{
"html": "<div style=\"padding: 10px 20px; border-radius: 5px; background-color: #e6e2ff; margin: 0 0 30px 0;\">\n <h5>Archive Method</h5>\n <p>Only on the full archive nodes. Complex queries might take longer and incur additional cost</p>\n</div>"
}
[/block]


### How to use it

{% code overflow="wrap" lineNumbers="true" %}

```typescript
// yarn add @tatumcom/js

import { TatumSDK, Tron, Network } from '@tatumcom/js'

const tatum = await TatumSDK.init<Tron>({network: Network.TRON})

const res = await tatum.rpc.broadcastHex('transactionHex')

await tatum.destroy() // Destroy Tatum SDK - needed for stopping background jobs
```

{% endcode %}

### Overview

The `broadcastHex` method is used to broadcast a signed transaction to the TRON network. This is a crucial step in performing operations on the blockchain, such as transferring TRX tokens or interacting with smart contracts.

The method requires the signed transaction in hexadecimal format.

### Parameters

`transaction` (string): The signed transaction in hexadecimal format. This is a required parameter.

### Return Object

The response object contains the following fields:

`result` (boolean): Whether the broadcast was successful. true - successful; false - failed, and this field will not be displayed in the returned result.

`txid` (string): The Transaction ID of the broadcasted transaction.

`code` (string): The error code in case the broadcast fails.

`message` (string): Detailed error information in case the broadcast fails.

`transaction` (Transaction):

- `raw_data.contract` - The main content of the transaction,`contract` is a list, but only one element is used at present. Different types of transactions have different contract contents. For example, for a TRX transfer type transaction, the contract will include the transfer amount, receiver address and other information. TRON supports multiple types of contracts, please refer to the official documentation [Types of Transaction](https://developers.tron.network/docs/tron-protocol-transaction#types-of-transaction).
- `raw_data.ref_block_bytes` - The height of the transaction reference block, using the 6th to 8th (exclusive) bytes of the reference block height, a total of 2 bytes. The reference block is used in the TRON TAPOS mechanism, which can prevent a replay of a transaction on forks that do not include the referenced block. Generally, the latest solidified block is used as the reference block.
- `raw_data.ref_block_hash` - The hash of the transaction reference block, using the 8th to 16th (exclusive) bytes of the reference block hash, a total of 8 bytes. The reference block is used in the TRON TAPOS mechanism, which can prevent a replay of a transaction on forks that do not include the referenced block. Generally, the latest solidified block is used as the reference block.
- `raw_data.expiration` - Transaction expiration time, beyond which the transaction will no longer be packed. If the transaction is created by calling the java-tron API, its expiration time will be automatically set by the node to the value of adding 60 seconds to the timestamp of the node's latest block. The expiration time interval can be modified in the node's configuration file, the maximum value cannot exceed 24 hours.
- `raw_data.data` - Transaction memo.
- `raw_data.timestamp` - Transaction timestamp, set as the transaction creation time.
- `raw_data.fee_limit` - The maximum energy cost allowed for the execution of smart contract transactions. Only deploying and triggering smart contract transactions need to be set, others not.
- `signature` - The sender's signature for the transaction. This proves that the transaction could only have come from the sender and was not sent fraudulently.
- `txID` - transaction id

### HTTP Request Example

```json
{
"transaction": "0A8A010A0202DB2208C89D4811359A28004098A4E0A6B52D5A730802126F0A32747970652E676F6F676C65617069732E636F6D2F70726F746F636F6C2E5472616E736665724173736574436F6E747261637412390A07313030303030311215415A523B449890854C8FC460AB602DF9F31FE4293F1A15416B0580DA195542DDABE288FEC436C7D5AF769D24206412418BF3F2E492ED443607910EA9EF0A7EF79728DAAAAC0EE2BA6CB87DA38366DF9AC4ADE54B2912C1DEB0EE6666B86A07A6C7DF68F1F9DA171EEE6A370B3CA9CBBB00"
}
```

### HTTP Response Example

```json
{
"result": false,
"code": "TAPOS_ERROR",
"txid": "38a0482d6d5a7d1439a50b848d68cafa7d904db48b82344f28765067a5773e1d",
"message": "Tapos check error.",
"transaction": "{\"raw_data\": {\"ref_block_bytes\": \"02db\",\"ref_block_hash\": \"c89d4811359a2800\",\"expiration\": 1560496575000,\"contract\": [{\"type\": \"TransferAssetContract\",\"parameter\": {\"type_url\": \"type.googleapis.com/protocol.TransferAssetContract\",\"value\": \"0a07313030303030311215415a523b449890854c8fc460ab602df9f31fe4293f1a15416b0580da195542ddabe288fec436c7d5af769d242064\"}}]},\"signature\": [\"8bf3f2e492ed443607910ea9ef0a7ef79728daaaac0ee2ba6cb87da38366df9ac4ade54b2912c1deb0ee6666b86a07a6c7df68f1f9da171eee6a370b3ca9cbbb00\"]}"
}
```
Loading

0 comments on commit 1bea23b

Please sign in to comment.