先復(fù)習(xí)一下基礎(chǔ)知識
連接波場網(wǎng)絡(luò):
// tronConnector.ts
import {
TronWeb } from 'tronweb';
export function connectToTronNetwork(fullNodeUrl: string, eventServerUrl: string): TronWeb {
const tronWeb = new TronWeb({
fullHost: fullNodeUrl || 'https://api.trongrid.io',
headers: {
'TRON-PRO-API-KEY': 'your api key' },
privateKey: 'your private key'
});
return tronWeb;
}
其中APIKEY可以在官網(wǎng)獲取;
可以使用tronWeb.isConnected()判斷是否連接成功
創(chuàng)建離線波場地址:
tronWeb.createAccount();
該地址未激活,如果需要激活, 通常需要一定數(shù)量的 TRX(TRON 的本地代幣)用于支付激活費用;
const toAddress = '新賬戶地址'; // 新創(chuàng)建的賬戶地址
const amount = 1000; // 轉(zhuǎn)賬的 TRX 數(shù)量
const transaction = await tronWeb.trx.sendTransaction(toAddress, amount);
console.log(transaction);
等待區(qū)塊確定
const accountInfo = await tronWeb.trx.getAccount('新賬戶地址');
console.log(accountInfo);
就可以查看激活信息;
創(chuàng)建隨機助記詞與私鑰:
const tronWeb = require('tronweb');
// 創(chuàng)建隨機的助記詞和私鑰
const {
mnemonic, privateKey } = tronWeb.createRandom();
console.log('Mnemonic:', mnemonic);
console.log('Private Key:', privateKey);
如何讓其助記詞與波場地址關(guān)聯(lián):
//使用上述的privateKey
const address = tronWeb.address.fromPrivateKey(privateKey);
console.log('Address:', address);
這就關(guān)聯(lián)了;文章來源:http://www.zghlxwxcb.cn/news/detail-756515.html
根據(jù)提供的助記詞獲取地址和私鑰文章來源地址http://www.zghlxwxcb.cn/news/detail-756515.html
const tronWeb = require('tronweb');
// 替換為實際的助記詞
const mnemonic = 'your twelve words mnemonic here';
// 從助記詞生成 TRON 賬戶的地址和私鑰
const account = tronWeb.fromMnemonic(mnemonic);
到了這里,關(guān)于web3Js(干貨)(多簽的流程原理)看完這一篇就懂了(波場網(wǎng)絡(luò)-請勿用于除學(xué)習(xí)外其他用途)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!