0
let Arg1, Arg2;

The above variables are global variables

admin_contract.on('MemberAdded',(arg1, arg2)=>{
    console.log(`event MemberAdded`);
    
    const EventObj={
      _arg1 : arg1,
      _arg2 : arg2,
    }
    
  });

I want to pass the value of _arg1, _arg2 inside Arg1, Arg2 How can I ?

1 Answer 1

2

I think your problem is not related to ethers.js, but just a Javascript problem...

Taking your code, what is passed to the arguments of the arrow function that you pass to on() are the event arguments that are emitted from your contract, so imagining this event:

event MemberAdded(string name, address account);

Then your code would be like:

admin_contract.on('MemberAdded', (name, account) => {
    console.log(`event MemberAdded`);
    
    const EventObj = {
      _arg1 : arg1,
      _arg2 : arg2,
    }    
});

and your globals arg1 and arg2 should be accessible and not shadowed by the arguments you were passing before.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.