invalid response sendTransaction - bsc pancakeswap approve #1602
Unanswered
YabberWalkie
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I've been trying to figure out now for hours why my cod isn't work and i just can't figure it out :(
All i'm receiving is an error message:
(node:31956) UnhandledPromiseRejectionWarning: Error: invalid response - sendTransaction
at WebSocketProvider.BaseProvider._wrapTransaction (E:\python\PancakeMix\node_modules@ethersproject\providers\lib\base-provider.js:1264:19)
at WebSocketProvider. (E:\python\PancakeMix\node_modules@ethersproject\providers\lib\base-provider.js:1336:52)
at step (E:\python\PancakeMix\node_modules@ethersproject\providers\lib\base-provider.js:48:23)
at Object.next (E:\python\PancakeMix\node_modules@ethersproject\providers\lib\base-provider.js:29:53)
at fulfilled (E:\python\PancakeMix\node_modules@ethersproject\providers\lib\base-provider.js:20:58)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
My code:
`
const ethers = require('ethers');
var config = require('./config.json')
const addresses = {
WBNB: '0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c',
factory: '0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73',
router: '0x10ED43C718714eb63d5aA57B78B54704E256024E',
recipient: '0x6013fE5de132862c4Ec0CCc2E0A023d2Ac845C0F'.toLocaleLowerCase()
}
//First address of this mnemonic must have enough BNB to pay for tx fess
const provider = new ethers.providers.WebSocketProvider(config.network);
const wallet = ethers.Wallet.fromMnemonic(config.mnemonic);
const account = wallet.connect(provider);
const router = new ethers.Contract(
addresses.router,
[
'function getAmountsOut(uint amountIn, address[] memory path) public view returns (uint[] memory amounts)',
'function swapExactTokensForTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts)'
],
account
);
const wbnb = new ethers.Contract(
addresses.WBNB,
[
'function approve(address spender, uint amount) public returns(bool)',
],
account
);
const init = async () => {
let overrides = {
gasPrice: 5000000000,
gasLimit: 500000
};
const tx = await wbnb.approve(
router.address,
ethers.utils.parseUnits('0.002', 'ether'),
overrides
);
const receipt = await tx.wait();
console.log('Transaction receipt');
console.log(receipt);
}
init();
`
My code that calls the function getAmountsOut does seem to work, however calling approve, or swapExactTokensForTokens from the other contract always fail with this error message.
I'm using the wss://apis.ankr.com/wss/ endpoint..
Beta Was this translation helpful? Give feedback.
All reactions