我将使用 ether js 交换 2 个 BSC 令牌。但我有这样的错误。这是我的代码。
`const address = [tokenIn, tokenOut]; const to = config[config.network].addresses.recipient;
try {
const wbnb_abi = [
'function approve(address spender, uint256 amount) external returns (bool)'
];
let iface = new ethers.utils.Interface(wbnb_abi);
var data = iface.encodeFunctionData('approve', [config[config.network].addresses.router, ethers.BigNumber.from("115792089237316195423570985008687907853269984665640564039457584007913129639935")]);
const txObj =
{
from: config[config.network].addresses.recipient,
to: tokenIn,
value: 0,
gasLimit: 144264, // 100000
gasPrice: gas_price,
data: data
}
try {
account.sendTransaction(txObj).then((transaction) => {
let iface = new ethers.utils.Interface(pancake_route_abi);
var data = iface.encodeFunctionData('swapExactTokensForTokens', [amountIn, amountOut, address, to, Date.now() + 1000 * 60 * 5]);
const txObj =
{
from: config[config.network].addresses.recipient,
to: config[config.network].addresses.router,
value: 0,
gasLimit: 144264, // 100000
gasPrice: gas_price, // 7000000000
data: data
}
try {
account.sendTransaction(txObj).then((transaction) => {
});
} catch (error) {
console.log("failed to send!!");
}
});
} catch (error) {
console.log("failed to send!!");
}
} catch (err) {
console.log(err)
}`
我不知道为什么会有这样的理由。帮我。