D'CENT developer guide
Official siteUser GuideBlogTwitter
  • Introduction
  • How to Connect Your DApp to D’CENT Mobile App
  • In-app browser (dapp browser)
    • Getting Started
    • EVM compatible networks
    • Klaytn network
    • Tron network
  • Dynamic Link
    • Dynamic Link to In-app Browser
    • EIP-681 : Transaction/Payment Request
  • D'CENT WalletConnect (DWC)
    • Introduction
    • Packages
    • D'CENT WalletConnect
    • Test Environment
    • WalletConnect monorepo
  • Collectibles
    • NFT list on Collectibles tab
  • D'CENT biometric wallet for PC
    • D'CENT SDK for PC Environment
    • dcent-web-connector
      • Configurations
      • Device & Accounts Info.
      • Address & XPUB
      • Ethereum & EVM compatible
      • Klaytn
      • Bitcoin
      • XRPL (XRP Ledger)
      • Hedera (HBAR & HTS)
      • Tron (TRX & TRC20)
      • Stellar
      • Tezos (XTZ & XTZ_FA)
      • Vechain
      • Near (NEAR & Near Token)
      • Havah
      • Polkadot
      • Polkadot Parachain
      • Cosmos & Cosmos compatible network
      • Algorand
    • dcent-cli-connector
      • Configurations
      • Device & Accounts Info.
      • Address & XPUB
      • Ethereum & EVM compatible
      • Hedera (HBAR & HTS)
    • dcent-provider
  • D'CENT BIOMETRIC WALLET FOR Mobile
    • D'CENT SDK for Mobile Environment
    • dcent-biometric-sdk-android
      • Setup
      • Initialize
      • Device & Accrouts Info
      • Address & XPUB
      • Bitcoin
      • Ethereum & EVM compatible
      • Klaytn
      • XRPL
      • Binance
      • Stellar
      • Tron
      • Cardano
      • Hedera
      • Stacks
      • Solana
      • Conflux
      • Polkadot
      • Cosmos
      • Tezos
      • Vechain
      • Near
      • Havah
      • Algorand
    • dcent-biometric-sdk-ios
      • Setup
      • Initialize
      • Device & Accrouts Info
      • Address & XPUB
      • Bitcoin
      • Ethereum & EVM compatible
      • Klaytn
      • XRPL
      • Binance
      • Stellar
      • Tron
      • Cardano
      • Hedera
      • Stacks
      • Solana
      • Conflux
      • Polkadot
      • Cosmos
      • Tezos
      • Vechain
      • Near
      • Havah
      • Algorand
  • D'CENT Integrated Packages
    • Web3Modal
    • web3-onboard
  • Misc.
    • Logo & Brand Guideline
Powered by GitBook
On this page
  • Sign Transaction
  • getTronSignedTransaction()
  • getTrcTokenSignedTransaction()

Was this helpful?

  1. D'CENT biometric wallet for PC
  2. dcent-web-connector

Tron (TRX & TRC20)

PreviousHedera (HBAR & HTS)NextStellar

Last updated 2 years ago

Was this helpful?

Sign Transaction

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

getTronSignedTransaction()

Supported Coin Type

  • TRON

Parameters

  • transactionJson: this value conforms JSON format of Transaction Types in

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

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.

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

getTrcTokenSignedTransaction()

Supported Coin Type

  • TRON_TRC_TOKEN

Parameters

  • Same as getTronSignedTransaction()

Returned response object

  • Same as getTronSignedTransaction()

Tron Docs