TypeError whenever I try to interact with Contract events #2854
Replies: 3 comments 7 replies
-
Can you include the abi and contract address with a snippet of code? Ethers doesn’t use Proxy in v5, so that seems weird. What backend are you using? Infura? MM? |
Beta Was this translation helpful? Give feedback.
-
Put the contract (and any other ethers objects you need to store) into a non-Vue object. The extra stuff Vue does to make data update everywhere automatically doesn't seem to play well with ethers. I had the contract in a simple Vue3 store, which was causing the issue. I moved the contract out of the store, and it works fine now.
became
I think that if you're storing the contract in a view / component, you'll need to move it into a js file that you import into the component. |
Beta Was this translation helpful? Give feedback.
-
Just wanted to add a little bit more info to someone that may be struggling with this as well. In Vue (as of Apr 2022), primitives / objects / etc in your Essentially, Vue will loop through the object returned in data() {
num: Object.freeze(69),
something: Object.freeze(new Something())
} Abdelrahman Anwad has a vey insightful blog post on this. Worth a read as he goes into details on "deep reactivity". However, the way I've structured my application, I need to have the contract on my state. Luckily, the Contract Connection code lives under the same component. So I added an extra connectToContract() {
const contract = new ethers.Contract(config.contractAddr, Contract.abi, provider.getSigner()) // at this point the object is still "pure"
this.raptrContract = contract // now i am storing it to my data which automatically becomes "reactive"
this.subscribeToContractEvents(contract)
},
subscribeToContractEvents(contract) {
contract.on("MyEvent", f => console.log(f))
} Hope this helps! :) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I am getting this error whenever I try to call event-related functions on a contract, such as
contract.listenerCount('UpdatedMessages')
or
contract.on('UpdatedMessages', ()=>{ ... })
Any ideas? It is a contract on the Polygon test net.
Beta Was this translation helpful? Give feedback.
All reactions