Ethers.io javascript - Transaction failed when trying to sell token
Ethers.io javascript - Transaction failed when trying to sell token
Loading saved threads...
Ahmed · External communityPost link
External question — Ethereum Stack Exchange
Author: Ahmed
Original post: https://ethereum.stackexchange.com/questions/102217
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
I am trying to sell a token using ethers.io and javascript. Some tokens result in an error when selling the token and i dont know what is causing the error.
async function selltoken() {
let wbnb = '0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c';
let targettoken = '0xcf6bb5389c92bdda8a3747ddb454cb7a64626c63';
console.log("this is tokenin : " + '0xcf6bb5389c92bdda8a3747ddb454cb7a64626c63');
console.log("This is tokenout: " + '0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c');
const abi = [
"function balanceOf(address owner) view returns (uint256)"
];
const contract = new ethers.Contract('0xcf6bb5389c92bdda8a3747ddb454cb7a64626c63', abi, account);
const balance = await contract.balanceOf('0xA26161CCEEDDe3d4830729278dae5A89883351A0');
const amounts = await router.getAmountsOut('1000000', [targettoken, wbnb]);
console.log("This is balance: " + ethers.BigNumber.from('1000000'));
const etheramount = ethers.utils.parseUnits('0.000148403', 'ether');
console.log("this is amountout min: " + etheramount);
var amountOutMin = amounts[1].sub(amounts[1].div(20));
console.log("this is ether min: " + amountOutMin);
var tx = await router.swapExactTokensForETHSupportingFeeOnTransferTokens(
balance,
amountOutMin,
[targettoken, wbnb],
addresses.recipient,
Math.floor(Date.now() / 1000) + 60 * 10,
{
gasPrice: ethers.utils.parseUnits('10', 'gwei'),
gasLimit: 1000000
} //10 minutes
);
const receipt = await tx.wait();
console.log(`Trade accepted: Receipt: ${receipt}`);
}
Quote
Report
Soham Zemse · External communityPost link
External answer — Ethereum Stack Exchange
Author: Soham Zemse
Original post: https://ethereum.stackexchange.com/a/102480
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
Etherscan shows
TRANSFER_FROM_FAILED
revert while tenderly shows out of gas. If those screenshots are not of different transactions, one of those can be wrong. Also if you post your transaction hash here in text format, it makes checking it out easier.
Does selling the tokens directly from the AMM's webapp work? If that does not work, it's likely that this is a scam token which prevents people from selling.
Quote
Report
Post Reply
Checking account access…