You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have created an ERC20 token with a function depositTokens which emits a "Trade" I'm listening to those events and running my task on that, all things are working fine on the local server but as I deploy on Vercel it doesn't listen to events or doing task on emission of event
Ethers Version
5.7.2
Search Terms
No response
Describe the Problem
I have created an ERC20 token with a function depositTokens which emits a "Trade" I'm listening to those events and running my task on that, all things are working fine on the local server but as I deploy on Vercel it doesn't listen to events or doing task on emission of event
Contract Code Snippet
event Trade( address indexed from, address indexed to, Mode indexed mode, uint256 amount, uint256 value, uint256 date, uint256 orderId );
I also tried the websocket
Server Code Snippet
`const express = require("express");
const cors = require("cors");
const ethers = require("ethers");
require('dotenv').config()
const { tokenAbi } = require("./utils/ABI");
const app = express();
const port = 5000;
app.use(cors());
app.use(express.json());
const _privateKey = String(process.env.PRIVATE_KEY);
const ethRpc = String(process.env.ETH_RPC_URL);
const ethRpcWs = String(process.env.ETH_RPC_URL_WS);
const maticRpc = String(process.env.MATIC_RPC_URL);
const maticRpcWs = String(process.env.MATIC_RPC_URL_WS);
const ethTokenAddress = String(process.env.ETH_TOKEN_ADDRESS);
const maticTokenAddress = String(process.env.MATIC_TOKEN_ADDRESS);
// console.log("DATA",{
// _privateKey,
// ethRpc,
// maticRpc,
// maticTokenAddress,
// ethTokenAddress
// })
app.get("/", async (req, res) => {
try {
res.status(200).json({ message: "Server is Live!" });
} catch (error) {
res.status(500).json(error);
}
});
const abi = tokenAbi; // Contract ABI
const ethTokenProviderWs = new ethers.providers.WebSocketProvider(ethRpcWs);
const ethTokenContractWs = new ethers.Contract(
ethTokenAddress,
abi,
ethTokenProviderWs
);
const ethTokenProvider = new ethers.providers.JsonRpcProvider(ethRpc);
const ethTokenWallet = new ethers.Wallet(_privateKey, ethTokenProvider);
const ethTokenContract = new ethers.Contract(
ethTokenAddress,
abi,
ethTokenWallet
);
const maticTokenProviderWs = new ethers.providers.WebSocketProvider(maticRpcWs);
const maticTokenContractWs = new ethers.Contract(
maticTokenAddress,
abi,
maticTokenProviderWs
);
const maticTokenProvider = new ethers.providers.JsonRpcProvider(maticRpc);
const maticTokenWallet = new ethers.Wallet(_privateKey, maticTokenProvider);
const maticTokenContract = new ethers.Contract(
maticTokenAddress,
abi,
maticTokenWallet
);
const init = async () => {
ethTokenContractWs.on(
"Trade",
async (from, to, mode, amount,_value, date, orderId, Event) => {
if (mode?.toString() == "0") {
console.log("Event received: eth");
try {
const tx = await maticTokenContract.fullfillOrder(
to,
amount.toString(),
orderId.toString(),
{
value:_value?.toString()
}
);
console.log("Transaction Hash:", tx.hash);
await tx.wait(); // Wait for the transaction to be mined
console.log("Token minted successfully!",{
to,
amount:amount.toString(),
orderId:orderId.toString(),
value:_value?.toString()
});
} catch (error) {
console.error("Error minting Token:", error);
}
}
}
);
maticTokenContractWs.on(
"Trade",
async (from, to, mode, amount,_value, date, orderId, Event) => {
if (mode?.toString() == "0") {
console.log("Event received: matic");
try {
const tx = await ethTokenContract.fullfillOrder(
to,
amount.toString(),
orderId.toString(),{
value:_value?.toString()
}
);
console.log("Transaction Hash:", tx.hash);
await tx.wait(); // Wait for the transaction to be mined
console.log("Token minted successfully!",{
to,
amount:amount.toString(),
orderId:orderId.toString(),
value:_value?.toString()
});
} catch (error) {
console.error("Error minting Token:", error);
}
}
}
);
}
init().catch((err) => {
console.log(err);
process.exit(1);
});
app.listen(port, () => {
console.log(
Example app listening on port ${port}
);});
`
help me if I'm missing out on something. thanks.
The text was updated successfully, but these errors were encountered: