簡體   English   中英

無松露:錯誤:數字最多只能安全存儲 53 位

[英]No Truffle : Error: Number can only safely store up to 53 bits

在將此問題標記為重復之前,請注意我沒有使用松露:)

所以問題是,每次我向我的智能合約發送交易時,我都會收到標題錯誤。

const express = require('express');
const router = express.Router();
const EthUtil = require('ethereumjs-util');
const wallet = require('ethereumjs-wallet');
const Tx = require('ethereumjs-tx');
const Web3 = require('web3');
const testNetWS = "ws://...:";
const web3 = new Web3(new Web3.providers.WebsocketProvider(testNetWS));
const parameters = require('./parameters.js');
const myContract = new web3.eth.Contract(parameters.getSCABI(), parameters.getSCAddress());
const nonceCounterMap = new Map();
const account = "0x9cc01300194131b04cf297d9a0ebbef0ae011241";
const privateKey = "0x...";



router.get('/sendTheSmartContract', async function(req,res,next){

  // nonce
  var nonce = await getNewMaxNonce(account);
  const nonceHex = web3.utils.toHex(nonce);

  // gasLimit
  const gasLimit = "0x59a5380"; //"0xE0000000"; // from genesis

  // Gas price
  var gasPriceInWei;
    await web3.eth.getGasPrice()
    .then(  function(value){
                gasPriceInWei = value;
            }
    );

  var gasPriceInWeiHex = web3.utils.toHex(gasPriceInWei);

  // Tw-x
  var dataTx = myContract.methods.saveString('Test').encodeABI();

  var rawTx = {
    "nonce": nonceHex,
    "gasPrice": 0,
    "gasLimit": gasLimit,
    "to": parameters.getSCAddress(),
    "data": dataTx,
    "value": '0x01',
    "chainId": 71242
  }

  var tx = new Tx(rawTx);
  tx.sign( EthUtil.toBuffer(privateKey) );

  var serializedTx = tx.serialize();
  web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex'))
  .on('transactionHash', async function(hash){ console.log("Transaction hash step , DONE : " + hash); })
  .on('confirmation', async function(conf){ console.log("Confirmation step , DONE : " + JSON.stringify(conf)); })
  .on('receipt', async function(result){ console.log("Receipt step , DONE : " + JSON.stringify(result)); })
  .on('error', async function(err){ console.log("Sending signed transaction operation , STATUS : FAILED !!");console.error(err); });

});

});

我正在使用 NodeJS 和 ExpressJS。 上面的代碼片段中有一個包含我的導入版本的列表:

    "ethereumjs-tx": "^1.3.7",
    "ethereumjs-util": "^6.1.0",
    "ethereumjs-wallet": "^0.6.3",
    "express": "~4.16.1",
    "morgan": "~1.9.1",
  • 一件非常重要的事情:我正在研究法定人數的私有區塊鏈。

如果我設置:

"gasPrice": gasPriceInWeiHex

我會得到另一個錯誤:

{"code":-32000,"message":"Gas price not 0"}

無論如何,當我發送此交易時,它會記錄在仲裁區塊鏈儀表板上,我可以看到交易,但不知何故,在“transactionHash”事件之后(例如: .on('transactionHash', ) 我得到:

Error: Number can only safely store up to 53 bits

我認為它來自 rawTx 對象,但我不知道我錯過了什么......我發現 Quorum 正在計算塊 Timestamp 以納秒為單位,但我不知道如何檢查這是否是導致或者如果這可能導致它。

你怎么認為?

問題不是代碼而是 web3 版本,在我更新到 web3 2.0.0 Alpha 1 之后

sudo npm install web3@2.0.0-alpha.1

一切正常。

PS:舊的 web3 版本是:web3 1.0.0 beta 52

強烈建議使用 3.x

所以我通過升級到 3.x 來解決這個問題。

npm i web3@3.0.0-rc.5

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM