0

I am tired of contant getting error below.

Each time I am truing to call a method from a NodeJS app that works on Debian 11, it causes it. I can call this method directly from REMIX and from the frontend with metamask. Please help | hints.PS I tried with HTTP and WSS provider, I can do a curl to INFURA project co I am not blocked. PM2 shows no issues with NodeJS app. except mentioned issue while call. I also tried to create COntract with and without options { from, gas }

 Error call ethAuthorizeAccount: ContractExecutionError: Error happened while trying to execute a function inside a smart contract, { cause: [Eip838ExecutionError: execution reverted] { cause: undefined, code: -32000, receipt: undefined, data: undefined }, code: 310, receipt: undefined } 

NodeJS impl:

require('dotenv').config(); const { Web3 } = require('web3'); const contractUtilsABI = require("./abi/latenight-utils_v2-1-0-abi.json"); const apiResponse = require("../helpers/apiResponse"); // Setup Web3 // const web3 = new Web3(new Web3.providers.HttpProvider(process.env.ETH_NODE_INFURA)); const web3WssProvider = new Web3.providers.WebsocketProvider(process.env.ETH_NODE_WSS_INFURA); const web3 = new Web3(web3WssProvider); const contractAddressUtils = process.env.CONTRACT_ADDRESS_UTILS; const key = process.env.ETH_PRIVKEY; const account = web3.eth.accounts.privateKeyToAccount(key); const contractUtils = createContract(contractAddressUtils, contractUtilsABI); contractUtils.defaultHardfork = 'shanghai'; function createContract(_contractAddr, _abi) { if (web3.utils.isAddress(_contractAddr) && Array.isArray(_abi)) { // const myContract = new web3.eth.Contract(abi, contractAddress); console.log('valid contract and abi'); const contract = new web3.eth.Contract(_abi, _contractAddr, {from:account.address, gas: 3000000}); return contract; } else { console.error('Invalid contract address or ABI'); } } exports.ethAuthorizeAccount = [ async (req, res) => { const params = req.body; try { web3.eth.accounts.wallet.add(account); const accounts = web3.eth.accounts.wallet; if (!accounts.length) { return console.log('no accounts found!'); } const address = web3.eth.accounts.wallet[0].address; if (web3.utils.isAddress(address)) { // The address is valid const checksumAddress = web3.utils.toChecksumAddress(address); if (address === checksumAddress) { console.log('The address is checksummed correctly'); const result = await contractUtils.methods.generateRandomBytes32().call().then(console.log); const block = await web3.eth.getBlockNumber(); console.log(`Latest block: ${block}`); console.log('\nCALL result: ', result); } else { console.error('The address is not checksummed correctly'); } } else { console.error('Invalid address'); } } catch (error) { console.error(`Error call ethAuthorizeAccount:`, error); apiResponse.ErrorResponse(res, error); } } ] 

Soidity Call:

function generateRandomBytes32() external view returns (bytes32) { // require(_seedNodeCli == seedNodeCli, "access denied"); // Combine block-related data with the sender's address and current timestamp return keccak256( abi.encodePacked( block.timestamp, // Current block timestamp block.number, // Block number block.prevrandao, // Block prevrandao (pseudo-randomness) msg.sender // Sender address ) ); } 

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.