下载

arrow_down

构建

arrow_down

更多

arrow_down
activityactivityactivityactivity
  • themelight
  • languageIcon

  • menu
Skip to Content

钱包标准

方法已支持
sign
setAddress
setNode
isConnected
signMessageV2
multiSign
disconnect
getVersion

provider

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

设置地址

设置默认的钱包地址,用于发送交易、查询余额、签名消息等操作。

  • 注意:这不会设置私钥,只是设置默认的“from”地址。
  • 如果你在调用 tronWeb.trx.sendTransaction() 等方法时没有显式指定地址,就会使用这个默认地址。
  • 通常会配合私钥或 TronLink 钱包一起使用。
tronWeb.setAddress('TXXXXXXX...');

设置节点

动态设置或替换当前的节点配置 —— 例如切换 FullNode、SolidityNode 或 EventServer 的 URL。

  • 通常只需要设置 fullNode,TronWeb 会在未单独指定时使用相同的 URL 作为其他节点。
  • 在连接私有链或自定义节点时尤其有用。
// Set FullNode tronWeb.setNode('fullNode', 'https://api.trongrid.io'); // Set SolidityNode tronWeb.setNode('solidityNode', 'https://api.trongrid.io'); // Set EventServer tronWeb.setNode('eventServer', 'https://api.trongrid.io');

连接

Preview

Parameters

interface TronConnectInput { method: 'tron_requestAccounts' }

Returns

interface TronConnectResult { code: number; message: string }

用法

// @param TronConnectInput // @return TronConnectResult await tronLink.request({ method: "tron_requestAccounts" });

试一试

Loading live editor...

断连

Returns

interface TronConnectResult { code: number; message: string }

用法

// @param TronConnectInput // @return TronConnectResult await tronLink.disconnect();

试一试

Loading live editor...

消息

Preview

Parameters

type signedMessageV2Input string;

Returns

type signedMessageV2Output string;

用法

// @param signedMessageV2Input // @return signedMessageOutput await tronWeb.trx.signMessageV2(message);

试一试

Loading live editor...

交易

Chrome
App
Preview
Preview
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);
Last updated on