属性(读取“getChainId”)"/>
Theta 网络(thetalab):TypeError:无法读取 null 的属性(读取“getChainId”)
下面是theta网络的官方链接
以下是我需要和配置 Theta 网络的东西
require('isomorphic-fetch'); //In order to get fetch working in Node
const express = require("express");
const BigNumber = require('bignumber.js');
const thetajs = require("@thetalabs/theta-js");
const Wallet = thetajs.Wallet;
const chainId = thetajsworks.ChainIds.Testnet;
const provider = new thetajs.providers.HttpProvider(chainId);
这是我在 Node Js 中实现的代码
我想使用 Node JS 中的 thetalab NPM 包从一个 theta 帐户到另一个 theta 帐户进行交易。
对于交易,我们需要发送方私钥、接收方公钥、theta 金额和 tfuel 金额
var privateKey = "0xf235351c3a8787121162e102dbc4cd79641441a8376dcb0ca46a71b78485c3eb"
const wallet = new Wallet(privateKey);
const address = wallet.address;
const thetaWeiToSend = '0';
const tfuelWeiToSend = '0.1'
const transactionCount = await provider.getTransactionCount(address);
const from = address;
const to = "0x02B74daDAd33040F16eB91d7Aafb1b181a3e7930";
const txData = {
sequence : transactionCount,
from: from,
outputs: [
{
address: to,
thetaWei: thetaWeiToSend,
tfuelWei: tfuelWeiToSend,
}
]
}
const transaction = new thetajs.transactions.SendTransaction(txData, chainId);
console.log('transaction', transaction)
const result = await wallet.sendTransaction(transaction);
console.log('result', result)
我在尝试传输 THETA 和 TFUEL 时遇到此错误
fund Transfer error TypeError: Cannot read properties of null (reading 'getChainId')
at Wallet.getChainId (D:\Kartik\Theta\node_modules\@thetalabs\theta-js\dist\thetajs.cjs.js:1629:30)
at Wallet.signTransaction (D:\Kartik\Theta\node_modules\@thetalabs\theta-js\dist\thetajs.cjs.js:1648:37)
at Wallet.sendTransaction (D:\Kartik\Theta\node_modules\@thetalabs\theta-js\dist\thetajs.cjs.js:1421:31)
at fundTransfer (D:\Kartik\Theta\thetatransfer.js:49:37)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
回答如下:
你没有在钱包中提供提供者确保你必须在钱包中提供提供者我正在使用库来传输 theta 和 tfule。
const transfer = async (from, to, privateKey, thetaWeiToSend, tfuelWeiToSend) => {
try {
const wallet = new Wallet(privateKey, provider);
const txData = {
from: from,
outputs: [
{
address: to,
thetaWei: thetaWeiToSend,
tfuelWei: tfuelWeiToSend,
}
]
}
const transaction = new SendTransaction.transactions.SendTransaction(txData);
const result = await wallet.sendTransaction(transaction);
console.log(result);
} catch (error) {
console.log(error)
return error;
}
}
const ten18 = (new BigNumber(10)).pow(18); // 10^18, 1 Theta = 10^18 ThetaWei, 1 Gamma = 10^ TFuelWei
const thetaWeiToSend = (new BigNumber(0));
const tfuelWeiToSend = (new BigNumber(1)).multipliedBy(ten18);
transfer('0xb66D945B021AcDE0Fc1c639616E1D3fC9Aa10584', '0x4E6CA5eCc47bA2dcDdd7A9961ED26f39e25Ab15c', '0x303bed7d1a962aed4e13536b8061e3e4232828ddd1e6b23abb6ab6d1400e034b', thetaWeiToSend, tfuelWeiToSend)
更多推荐
Theta 网络(thetalab):TypeError:无法读取 null 的属性(读取“getChainId”)
发布评论