Skip to content

Tron

When running a DApp in the Bitget Wallet App and in the Chrome browser with the installed Chrome Extension, you can obtain the global objects window.bitkeep.tronLink and window.bitkeep.tronWeb for subsequent API calls.

js
const tronLink = window.bitkeep.tronLink;
const tronWeb = window.bitkeep.tronWeb;
const tronLink = window.bitkeep.tronLink;
const tronWeb = window.bitkeep.tronWeb;

Properties and methods of the injected objects

  • sign - (transaction, privateKey = false, useTronHeader = true, callback = false) => object: Sign a transaction
  • setAddress - (address = '', name = 'primaryAccountOnly', type = 1) => void: Set an address
  • setNode - (node) => void: Set a node
  • isConnected - () => Boolean: Get the connection status
  • signMessageV2 - (message) => void: Sign a message
  • multiSign - (transaction, privateKey, permissionId = 0) => void: Multi-sign a transaction
  • disconnect - () => void: Disconnect
  • getVersion - () => string: Get version information

Get Account Information

js
try {
  await tronLink.request({ method: "tron_requestAccounts" });
  const address = tronWeb.defaultAddress.base58;
  const balance = await tronWeb.trx.getBalance(address);
} catch {}
try {
  await tronLink.request({ method: "tron_requestAccounts" });
  const address = tronWeb.defaultAddress.base58;
  const balance = await tronWeb.trx.getBalance(address);
} catch {}

Wallet Connection Status

js
tronWeb.ready;
tronWeb.ready;

Send Transaction

Transaction

js
var tx = await tronweb.transactionBuilder.sendTrx(
  "TW8u1VSwbXY7o7H9kC8HmCNTiSXvD69Uiw",
  1000000,
  tronWeb.defaultAddress.base58
);
var signedTx = await tronweb.trx.sign(tx);
var broadcastTx = await tronweb.trx.sendRawTransaction(signedTx);
console.log(broadcastTx);
console.log(broadcastTx.txid);

// Token
let decimal = 18;
let Contract = await tronWeb
  .contract()
  .at("TLa2f6VPqDgRE67v1736s7bJ8Ray5wYjU7"); // WIN
const decimalCall = Contract.decimals || Contract.DECIMALS;
if (decimalCall) {
  decimal = await decimalCall().call();
}
let broadcastTx = await Contract.transfer(
  "TW8u1VSwbXY7o7H9kC8HmCNTiSXvD69Uiw",
  // "0xde0b6b3a7640000"
  tronWeb.toHex(2 * Math.pow(10, decimal))
).send(); // { feeLimit: 10000000 }

console.log(broadcastTx);
var tx = await tronweb.transactionBuilder.sendTrx(
  "TW8u1VSwbXY7o7H9kC8HmCNTiSXvD69Uiw",
  1000000,
  tronWeb.defaultAddress.base58
);
var signedTx = await tronweb.trx.sign(tx);
var broadcastTx = await tronweb.trx.sendRawTransaction(signedTx);
console.log(broadcastTx);
console.log(broadcastTx.txid);

// Token
let decimal = 18;
let Contract = await tronWeb
  .contract()
  .at("TLa2f6VPqDgRE67v1736s7bJ8Ray5wYjU7"); // WIN
const decimalCall = Contract.decimals || Contract.DECIMALS;
if (decimalCall) {
  decimal = await decimalCall().call();
}
let broadcastTx = await Contract.transfer(
  "TW8u1VSwbXY7o7H9kC8HmCNTiSXvD69Uiw",
  // "0xde0b6b3a7640000"
  tronWeb.toHex(2 * Math.pow(10, decimal))
).send(); // { feeLimit: 10000000 }

console.log(broadcastTx);