I have my contract:
const contract = new ethers.Contract(contractAddress, ABI, wsProvider)
and am listening to events.
contract.on("Transfer", async (from, to, value, event) => {
try {
if (from === contractAddress) {
console.log("Coins were sold");
} else if (to === contractAddress) {
console.log("Coins were bought");
} else {
console.log("Coins were transferred between wallets");
}
} catch (error) {
console.error("Error:", error.message);
}
});
But all I ever get is the “Coins were transferred between wallets” log. What am I missing here?
Tried: Multiple ways of checking adddresses against eachother to determine a buy or a sell
New contributor
Erik is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.