Hi,
Is it possible to use Dex Swap from NodeJS script?
I tried as follow:
const serverUrl = process.env.MORALIS_SERVER_URL;
const appId = process.env.MORALIS_APP_ID;
Moralis.start({ serverUrl, appId });
// Set provider
const provider = new Web3.providers.HttpProvider(
“https://speedy-nodes-nyc.moralis.io/1a2b3c4d5e6f1a2b3c4d5e6f/bsc/mainnet”
);
const web3 = new Web3(provider);
// Set account
const account = web3.eth.accounts.privateKeyToAccount(
process.env.WALLET_PRIVATE_KEY
);
// Swap
await Moralis.initPlugins();
dex = Moralis.Plugins.oneInch;
const options = {
chain: “eth”,
fromTokenAddress: “0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE”,
toTokenAddress: “0x111111111117dc0aa78b770fa6a738034120c302”,
amount: Number(Moralis.Units.ETH(“0.001”)),
fromAddress: account.address,
slippage: 0,
};
var receipt = await dex.swap(options);
console.log(receipt);
But always get this error:
Error: Missing web3 instance, make sure to call Moralis.enableWeb3() or Moralis.authenticate()
I tried different solutions but no luck… Thanks in advance!