im new in web3js and i got a problem. Would be nice, if you could help me. Ive been trying to solve it myself for days...
Im trying to simulate a buy transaction (after its working i will do the sell part), to check if buys (and sells) would success. but im getting this error: "Error: Returned error: execution reverted: PancakeLibrary: INSUFFICIENT_INPUT_AMOUNT"
but i have enough bnb in my wallet. What am i doing wrong? here is my code:
var Web3 = require("web3");
var web3 = new Web3(new Web3.providers.HttpProvider('https://bsc-dataseed.binance.org/'));
var panabi = JSON.parse(fs.readFileSync('panabi.json', 'utf-8'));
var MY_ADDRESS = "0x....";
var WBNB_ADDRESS = "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c"; // spend
var TokenAddress = "0x8076c74c5e3f5852037f31ff0093eeb8c8add8d3"; //Token to buy
var PANCAKESWAP_ROUTER_ADDRESS = "0x10ED43C718714eb63d5aA57B78B54704E256024E";
let contract = new web3.eth.Contract(panabi, PANCAKESWAP_ROUTER_ADDRESS);
// First step: Execute a buy for specific token. Since I don't want to send that
// transaction to blockchain, I'm just calling that function and see its result
var tx = new web3.eth.getTransactionCount(MY_ADDRESS, (err, result) => { console.log(result) });
var batch = new web3.eth.BatchRequest();
var callback = batch.add(
contract.methods.swapExactETHForTokens(
web3.utils.toHex(0), //slippage
[WBNB_ADDRESS, TokenAddress],
MY_ADDRESS,
web3.utils.toHex(Math.round(Date.now() / 1000) + 60 * 20)
)
.call
.request({
gasLimit: web3.utils.toHex(2000000),
gasPrice: web3.utils.toHex(web3.utils.toWei('7', 'gwei')),
value: web3.utils.toHex(web3.utils.toWei('0.01', 'ether')),
nonce: web3.utils.toHex(tx)
}, 'latest', callback)
);
console.log(callback); // this line should log response of your query```