no receipt, it doesnāt get that far. seems to be a parsing error, I tried this code variation and same thing basically, ParseError: 141 [object Object].
async function trySwap(fromTokenAddr, toTokenAddr, values) {
const pluginList = Moralis.Plugins;
console.log(pluginList);
const address = Moralis.User.current().get("ethAddress");
const amount = Moralis.Units.Token(values.tokenSellAmt).toString();
console.log("amount:", amount);
if (fromTokenAddr !== "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE") {
await Moralis.Plugins.oneInch
.hasAllowance({
chain: 'bsc', // The blockchain you want to use (eth/bsc/polygon)
fromTokenAddress: fromTokenAddr, // The token you want to swap
fromAddress: address, // Your wallet address
amount,
})
.then(async (allowance) => {
console.log(allowance);
if (!allowance) {
await Moralis.Plugins.oneInch.approve({
chain: 'bsc', // The blockchain you want to use (eth/bsc/polygon)
tokenAddress: fromTokenAddr, // The token you want to swap
fromAddress: address, // Your wallet address
});
}
})
.catch((e) => alert(e.message));
}
await doSwap(fromTokenAddr, toTokenAddr, address, amount)
.then((receipt) => {
console.log("receipt status code: ", receipt);
if (receipt.statusCode !== 400) {
alert("Swap Complete");
setTimeout(() => {
window.location.reload("/");
}, 500);
}
// else {
// alert("Receipt - Not enough balance!");
// }
})
.catch((e) => {
console.log("error: ", e);
alert(e);
});
}
async function doSwap(fromTokenAddr, toTokenAddr, userAddress, amount) {
return await Moralis.Plugins.oneInch.swap({
chain: 'bsc', // The blockchain you want to use (eth/bsc/polygon)
fromTokenAddress: fromTokenAddr, // The token you want to swap
toTokenAddress: toTokenAddr, // The token you want to receive
amount: Moralis.Units.Token(amount).toString(),
fromAddress: userAddress, // Your wallet address
slippage: 15,
});
}
i was able to buy with BNB before with this doswap function, tried both somthing else changed. not sure what?
async function doSwap(fromTokenAddr, toTokenAddr, userAddress, amount) {
const options = {
chain: "bsc", // The blockchain you want to use (eth/bsc/polygon)
fromTokenAddress: fromTokenAddr, // The token you want to swap
toTokenAddress: toTokenAddr, // The token you want to receive
amount: amount,
fromAddress: userAddress, // Your wallet address
slippage: 15,
};
var receipt = await dex.swap(options)
console.log(receipt);
}