Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contract should call suscribeToGlobalEvents in constructor #5817

Closed
spacesailor24 opened this issue Feb 7, 2023 · 0 comments
Closed

Contract should call suscribeToGlobalEvents in constructor #5817

spacesailor24 opened this issue Feb 7, 2023 · 0 comments
Assignees
Labels
4.x 4.0 related

Comments

@spacesailor24
Copy link
Contributor

Doing the following seems to be problematic for Contract.clone and the Web3.ContractBuilder. In order to implement the following fixes with need to be investigated further than the scope of #5756

Originally posted by @spacesailor24 in #5756 (comment)

I think contractContext is just a copy of the context, which comes from self.getContextObject() here (any case), and subscribing doesn't have the effect we want.

@nikoulai contractContext is not a copy, it's a reference to the Web3Context the user is providing

const web3Context = new Web3Context('http://127.0.0.1:8545');
web3Context.defaultBlock = 'pending';

const contract = new Contract([], { syncWithContext: true }, web3Context);
console.log(contract.defaultBlock); // latest

web3Context.defaultBlock = 'earliest';

console.log(contract.defaultBlock); // earliest

(the console.log(contract.defaultBlock); // latest is a bug, as contract.defaultBlock should be pending as it's supposed to be set by web3Context)

The above code works as expected, but only if the following

if (contractContext !== undefined) {
    this.suscribeToGlobalEvents(contractContext);
}

occurs after the new line:

this.syncWithContext = (options as ContractInitOptions)?.syncWithContext ?? false;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.x 4.0 related
Projects
None yet
Development

No branches or pull requests

2 participants