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

Fix @celo/connect README code example #144

Merged
merged 2 commits into from
Feb 16, 2024
Merged

Conversation

arthurgousset
Copy link
Contributor

@arthurgousset arthurgousset commented Feb 16, 2024

Description

Fixes the code example in the @celo/connect README.

const web3 = new Web3("YOUR_RPC_URL")
const connection = new Connection(web3)

- connection.setProvider()

connection.setProvider() doesn't need to be called explicitly with a CeloProvider, because connection is already configured with a CeloProvider in the constructor:

setProvider(provider: Provider) {
if (!provider) {
throw new Error('Must have a valid Provider')
}
this._chainID = undefined
try {
if (!(provider instanceof CeloProvider)) {
this.rpcCaller = new HttpRpcCaller(provider)
provider = new CeloProvider(provider, this)
}
this.web3.setProvider(provider as any)
return true
} catch (error) {
console.error(`could not attach provider`, error)
return false
}
}

Related

Tested

Docs only change

Backwards compatibility

Yes

Documentation

Yes

Copy link

changeset-bot bot commented Feb 16, 2024

⚠️ No Changeset found

Latest commit: a884b24

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@arthurgousset
Copy link
Contributor Author

arthurgousset commented Feb 16, 2024

@nicolasbrugneaux I'm looking for the lines that set the CeloProvider in the connection constructor.
But I can't find it

constructor(readonly web3: Web3, public wallet?: ReadOnlyWallet, handleRevert = true) {
web3.eth.handleRevert = handleRevert
this.config = {
gasInflationFactor: 1.3,
}
const existingProvider: Provider = web3.currentProvider as Provider
this.setProvider(existingProvider)
// TODO: Add this line with the wallets separation completed
// this.wallet = _wallet ?? new LocalWallet()
this.config.from = web3.eth.defaultAccount ?? undefined
this.paramsPopulator = new TxParamsNormalizer(this)
}

Can you help me find it again?

@arthurgousset
Copy link
Contributor Author

Ah my bad, it's here

setProvider(provider: Provider) {
if (!provider) {
throw new Error('Must have a valid Provider')
}
this._chainID = undefined
try {
if (!(provider instanceof CeloProvider)) {
this.rpcCaller = new HttpRpcCaller(provider)
provider = new CeloProvider(provider, this)
}
this.web3.setProvider(provider as any)
return true
} catch (error) {
console.error(`could not attach provider`, error)
return false
}
}

@arthurgousset arthurgousset marked this pull request as ready for review February 16, 2024 14:08
@arthurgousset arthurgousset requested a review from a team as a code owner February 16, 2024 14:08
@arthurgousset arthurgousset enabled auto-merge (squash) February 16, 2024 14:09
@arthurgousset arthurgousset merged commit 34de1b8 into master Feb 16, 2024
18 checks passed
@arthurgousset arthurgousset deleted the arthurgousset/README branch February 16, 2024 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants