【问题标题】:Getting error in web3.js regarding write tx在 web3.js 中出现关于 write tx 的错误
【发布时间】:2020-09-17 01:46:09
【问题描述】:

您好,我遇到了错误

Error: [ethjs-query] while formatting inputs '[{"0":false}]' for method 'getTransactionReceipt' error: Error: [ethjs-format] hex string '[object Object]' must be an alphanumeric 66 utf8 byte hex (chars: a-fA-F) string, is 0 bytes
    at ethjs.min.js:11
    at new Promise (<anonymous>)
    at i.getTransactionReceipt (ethjs.min.js:11)
    at i.e.<computed> [as getTransactionReceipt] (ethjs.min.js:11)
    at ethjs.min.js:11

我正在调用智能合约投资功能:

function invest()public payable onlyAmount() firstExist  returns(bool){    

//  balances[msg.sender]=msg.value;
 invested[msg.sender]+= msg.value;
 isInvested[msg.sender]=true;
 users[msg.sender].creationTime=now;
  commission=(msg.value.mul(10)).div(100);
 forCreators(commission);
emit Invest(msg.sender,msg.value);
 return true;
}

我在哪里像从 web3.js 调用函数一样

tokenContract.invest({
    from: user_address,
    gasLimit: web3.toHex(8000000),
    gasPrice: web3.toHex(web3.toWei('10', 'gwei')),
    value : web3.toHex( web3.toWei(0.25, 'ether'))

  })
  .then(txHash =>  eth.getTransactionSuccess(txHash)
      .then(receipt => {
        alert("Sigup Has been successful",receipt);
      })
  )
  .catch((err) => {
    alert("Error couldnot signUp");
    console.log(err);
  })

所有写入功能都显示此错误.. 读取工作正常。我以前从未遇到过这个错误。我尝试在 Ropsten 和 Rinkeby 上部署合同同样的错误。 这些合约功能在 etherscan 和 remix 上运行良好。 在 web3js 中,甚至 Metamask 也不会出现在事务中。可能是什么问题?

【问题讨论】:

  • 我正在使用

标签: blockchain ethereum smartcontracts web3js


【解决方案1】:

正如我上面提到的,我使用的是 eth.js 。所以不知何故,这就是问题所在。我通过不使用 ethjs 而只是使用 web3js 来解决这个问题。由于我已经实现了节点应用程序的所有读取功能和所有功能,因此更改所有内容是浪费时间。从 ethjs(用于读取)和纯 web3js 制作 2 个差异变量 1 和 1

const NameContract = web3.eth.contract(tokenABI);
window.tokenContract2 = NameContract.at(tokenAddress); //web3js


 window.tokenContract = eth.contract(tokenABI).at(tokenAddress); ethjs

然后我使用了像

这样的功能
tokenContract2.regUser({ from: user_address, gas: 400000 },
(err, res) => { /** callback **/ }
)

回调是必要的,因为元掩码会发出错误。

我仍然想知道问题的根源。但由于我的时间不多,我不得不推进这个项目

【讨论】:

    猜你喜欢
    • 2022-08-16
    • 2018-12-11
    • 1970-01-01
    • 2020-01-28
    • 2021-09-22
    • 1970-01-01
    • 2019-04-23
    • 2022-01-23
    • 1970-01-01
    相关资源
    最近更新 更多