I am trying to sell a token (DOBO). Buying DOBO is no problem and it goes through. But I cannot sell it. I get a failed transaction, but no error message on node.js (see https://bscscan.com/tx/0x2a1e3af0c800dc1280c5f5a7e45cdb1a8914f2dcd66a63cd44ba397411a30442). I have sufficient DOBO and sufficient BNB in my wallet. At first I thought it is because DOBO was not approved on Pancakeswap. I tried implementing approval in code (see below), but that didn't work. I eventually approved it manually, but I still get a failed sell transaction.
Why can't I approve the token sale? Why do I get an error when trying to sell the token?
Thanks for your help!
const ethers = require('ethers');
const WSS = "wss:/XXX" // NODE CONNECTION
const Seed = 'XXX XXX' // WALLET SEEDPHRASE
const recipientaddress = '0x8d25C18e2280A05aF12c2620388116Fb2a72a236' // WALLET ADDRESS
const routeraddress = '0x10ed43c718714eb63d5aa57b78b54704e256024e' // PANCAKESWAP ROUTER
const amountIn = ethers.utils.parseUnits('10', 'ether'); // SELL 10 DOBO
const minBuy = ethers.utils.parseUnits('0', 'ether') // NO MINIMUM
const shitCoin = 'ae2df9f730c54400934c06a17462c41c08a06ed8'; // DOBO
const moneyToken = 'bb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c'; // wBNB
const provider = new ethers.providers.WebSocketProvider(WSS);
const wallet = ethers.Wallet.fromMnemonic(Seed);
const account = wallet.connect(provider);
const router = new ethers.Contract(
routeraddress,
['function swapExactTokensForTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts)'],
account
);
// APPROVE TOKEN
const fullToken1 = ("0x"+shitCoin); // DOBO
const approveToken = new ethers.Contract(
fullToken1,
[
'function approve(address spender, uint amount) public returns(bool)',
],
account
);
const init = async () => {
const tx = await approveToken.approve(
routeraddress,
'1000' // APPROVE TRADING 1000 DOBO?
);
const receipt = await tx.wait();
console.log('Transaction receipt');
console.log(receipt);
}
// SELL TOKEN
router.swapExactTokensForTokens(
amountIn, // 10 DOBO
minBuy, // set to 0
[shitCoin, moneyToken],
recipientaddress,
Date.now() + 1000 * 60 * 10,
{
gasPrice: ethers.utils.parseUnits('10', 'gwei'),
gasLimit: '2100000'
}
)