I have a contract on polygon and I want to call a write function setPrice(uint256 _price)
but when I run this code then I am getting an error:
{ code: -32000, message: 'transaction underpriced' }
Smart Contract: https://polygonscan.com/address/0x8835c31178f8f3407d4588be49532de1c02c3a04
this is my code:
const Web3 = require("web3");
const WalletProvider = require("@truffle/hdwallet-provider");
const http = require("http");
const { release } = require("os");
const mysql = require('mysql');
const conn = mysql.createConnection({
host: "localhost",
user: "root",
password: "",
database:"nft",
});
conn.connect(function(err) {
if (err) throw err;
//console.error("Connected!");
});
let provider = new WalletProvider({
mnemonic: {
phrase: '*****myWalletPhrase*****'
},
providerOrUrl: "https://rpc-mainnet.matic.quiknode.pro/"
});
const web3 = new Web3(provider);
const dexABI ="smartContractAbi";
const contract_address = "0x8835c31178F8f3407d4588Be49532De1c02C3A04";
const contract = new web3.eth.Contract(dexABI, contract_address);
function toFixed(x) {
// some code
}
http.createServer(async (req, res) => {
if(req.url != '/favicon.ico')
{
try {
const accounts = await web3.eth.getAccounts();
//console.error(accounts);
let user= accounts[6];
let amount=0;
conn.query(`SELECT * FROM dollor_rate`, async function(err,result){
if (err) return err;
console.error("this",result[0].usd_rate);
amount=toFixed(result[0].usd_rate).toString();
await contract.methods.setPrice(''+amount).send({from:user,gas:21000},function(err1,receipt){
if(err1)
console.error("Error==>",err1);
else
console.error("Erorr1=======",receipt);
});
});
} catch (error) {
console.log(error);
}
res.end();
}
})
.listen(8080);