'Web3.js returned error: execution reverted

I'm new to blockchain programming and web3 and I don't really understand the error. I'm trying to call a function from my smart contract (on BSC test net)

Function is called getRandom

app.js

const Web3 = require("web3");
const web3 = new Web3("https://speedy-nodes-nyc.moralis.io/redacted/bsc/testnet");
const key = "28e........................8"
const contract = new web3.eth.Contract([
    {
        "inputs": [],
        "name": "getRandom",
        "outputs": [
            {
                "internalType": "uint256",
                "name": "",
                "type": "uint256"
            }
        ],
        "stateMutability": "nonpayable",
        "type": "function"
    }
], "0x22191A37B2AB83e7A81758ecd0E120cf080153B1")

const account = web3.eth.accounts.privateKeyToAccount('0x' + key);
web3.eth.accounts.wallet.add(account);

(async () => {
    try {
        const gasPrice = await web3.eth.getGasPrice();
        const gasEstimate = await contract.methods.getRandom().estimateGas({from: account.address});

        console.log(contract.methods.getRandom().send({from: account.address, gasPrice: gasPrice, gas: gasEstimate}))
    }
    catch (e) {
        console.log(e)
    }
})();

Error

Error: Returned error: execution reverted
    at Object.ErrorResponse (C:\DeFi project\node_modules\web3-core-helpers\lib\errors.js:28:19)
    at C:\DeFi project\node_modules\web3-core-requestmanager\lib\index.js:302:36
    at XMLHttpRequest.request.onreadystatechange (C:\DeFi project\node_modules\web3-providers-http\lib\index.js:98:13)
    at XMLHttpRequestEventTarget.dispatchEvent (C:\DeFi project\node_modules\xhr2-cookies\dist\xml-http-request-event-target.js:34:22)
    at XMLHttpRequest._setReadyState (C:\DeFi project\node_modules\xhr2-cookies\dist\xml-http-request.js:208:14)
    at XMLHttpRequest._onHttpResponseEnd (C:\DeFi project\node_modules\xhr2-cookies\dist\xml-http-request.js:318:14)
    at IncomingMessage.<anonymous> (C:\DeFi project\node_modules\xhr2-cookies\dist\xml-http-request.js:289:61)
    at IncomingMessage.emit (events.js:327:22)
    at endReadableNT (internal/streams/readable.js:1327:12)
    at processTicksAndRejections (internal/process/task_queues.js:80:21) {
  data: null
}

I'm just trying to get the response from my smart contract's function.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source