Reputation: 599
before marking this question as a duplicate please notice that I'm not using truffle :)
So the problem is , everytime I send a transaction to my smart contract I get the error from title.
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); });
});
});
I'm using NodeJS & ExpressJS. There's a list with the versions of my imports from the code snippet above :
"ethereumjs-tx": "^1.3.7",
"ethereumjs-util": "^6.1.0",
"ethereumjs-wallet": "^0.6.3",
"express": "~4.16.1",
"morgan": "~1.9.1",
If I set :
"gasPrice": gasPriceInWeiHex
I would get another error :
{"code":-32000,"message":"Gas price not 0"}
When I send this transaction , anyway , it's recorded on quorum blockchain dashboard and I can see the transaction , but somehow , after the "transactionHash" event ( e.g : .on('transactionHash',
) I get :
Error: Number can only safely store up to 53 bits
I think it's from the rawTx object , but I don't know what I'm missing... I've found that Quorum is calculating the block Timestamp was in nanoseconds , but I don't know how can I check if that's the cause or if that might cause it.
What do you think?
Upvotes: 3
Views: 918
Reputation: 305
It is highly recommend to use 3.x
So I resolve this by upgrading to 3.x.
npm i [email protected]
Upvotes: 0
Reputation: 599
The problem was not the code but the web3 version , after I've updated to web3 2.0.0 Alpha 1
sudo npm install [email protected]
everything worked.
PS : Old web3 version was : web3 1.0.0 beta 52
Upvotes: 2