docs(embedded-wallets): fix broken EVM snippets in integration guide - #3058
Open
callumweb3 wants to merge 1 commit into
Open
callumweb3 wants to merge 1 commit into
callumweb3 wants to merge 1 commit into
Conversation
## Summary
Fixes several broken snippets in
`embedded-wallets/sdk/js/_ethereum-integration-snippets.mdx`.
All issues verified locally with Node.js v24 and ethers 6.17.0.
## Fixes
### 1. Deploy contract (ethers) — SyntaxError + ethers v5 API
const address = signer.getAddress();
const contractFactory = new ContractFactory(JSON.parse(JSON.stringify(contractABI), contractByteCode, address);
const contract = await contractFactory.deploy("Hello World!");
const receipt = await contract.deployed();
- Unbalanced parentheses: `ContractFactory(` and `JSON.parse(` are
opened, only one is closed. `node --check` reports
`SyntaxError: missing ) after argument list`.
- `JSON.parse` receives three arguments — `(text, reviver)` only;
`contractByteCode` lands in `reviver`, `address` is ignored.
- `JSON.parse(JSON.stringify(contractABI))` is unnecessary — ABI is
already an array, ethers v6 accepts it directly.
- `signer.getAddress()` is missing `await` (returns `Promise<string>`
in v6), and the variable is unused in the snippet.
- `contract.deployed()` is v5 API. In ethers 6.17.0
`Contract.prototype.deployed` is `undefined`; the v6 replacement is
`waitForDeployment()` + `getAddress()`.
- `signer` was not defined in this snippet — added
`new ethers.BrowserProvider(provider)` + `getSigner()`, matching the
other ethers snippets in the file.
After:
const contractFactory = new ContractFactory(contractABI, contractByteCode, signer);
const contract = await contractFactory.deploy("Hello World!");
await contract.waitForDeployment();
const deployedContractAddress = await contract.getAddress();
### 2. Deploy contract (viem) — stray `this.`
const publicClient = createPublicClient({
chain: this.getViewChain(),
transport: custom(provider),
})
...
abi: this.contractABI,
bytecode: this.contractByteCode,
In an ESM module `this` is `undefined` inside a plain function, so
these lines throw
`TypeError: Cannot read properties of undefined (reading 'getViewChain')`.
Replaced with `mainnet`, `contractABI`, `contractByteCode` (already
declared above in the same snippet), matching the other viem tabs.
### 3. Write to contract (viem) — undeclared `address`
address = await walletClient.getAddresses()
Missing `const` — `ReferenceError: address is not defined` under ESM.
Fixed to `const address = ...`, consistent with the rest of the file.
### 4. Read / Write contract (ethers) — drop redundant ABI round-trip
`JSON.parse(JSON.stringify(contractABI))` removed from both
`new ethers.Contract(...)` calls. Aligned with fix MetaMask#1.
## Scope
- Documentation only; one file; four logical changes.
- No behavior change.
## Verification
Reproduced with Node.js v24.13.1 and ethers 6.17.0:
- `node --check` on the current Deploy (ethers) snippet →
`SyntaxError: missing ) after argument list` (screenshot attached).
- `typeof ethers.Contract.prototype.deployed === "undefined"`,
`typeof ethers.BaseContract.prototype.waitForDeployment === "function"`.
- `const address = signer.getAddress()` → `typeof address === "object"`,
`address instanceof Promise === true`; with `await` → `typeof === "string"`.
|
@callumweb3 is attempting to deploy a commit to the Consensys Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes several broken snippets in
embedded-wallets/sdk/js/_ethereum-integration-snippets.mdx. All issues verified locally with Node.js v24 and ethers 6.17.0.Fixes
1. Deploy contract (ethers) - SyntaxError + ethers v5 API
ContractFactory(andJSON.parse(are opened, only one is closed.node --checkreportsSyntaxError: missing ) after argument list.JSON.parsereceives three arguments -(text, reviver)only;contractByteCodelands inreviver,addressis ignored.JSON.parse(JSON.stringify(contractABI))is unnecessary - ABI is already an array, ethers v6 accepts it directly.signer.getAddress()is missingawait(returnsPromise<string>in v6), and the variable is unused in the snippet.contract.deployed()is v5 API. In ethers 6.17.0Contract.prototype.deployedisundefined; the v6 replacement iswaitForDeployment()+getAddress().signerwas not defined in this snippet - addednew ethers.BrowserProvider(provider)+getSigner(), matching the other ethers snippets in the file.After:
2. Deploy contract (viem) - stray
this.In an ESM module
thisisundefinedinside a plain function, so these lines throwTypeError: Cannot read properties of undefined (reading 'getViewChain'). Replaced withmainnet,contractABI,contractByteCode(already declared above in the same snippet), matching the other viem tabs.3. Write to contract (viem) - undeclared
addressMissing
const-ReferenceError: address is not definedunder ESM. Fixed toconst address = ..., consistent with the rest of the file.4. Read / Write contract (ethers) - drop redundant ABI round-trip
JSON.parse(JSON.stringify(contractABI))removed from bothnew ethers.Contract(...)calls. Aligned with fix #1.Scope
Verification
Reproduced with Node.js v24.13.1 and ethers 6.17.0:
node --checkon the current Deploy (ethers) snippet >SyntaxError: missing ) after argument list:typeof ethers.Contract.prototype.deployed === "undefined",typeof ethers.BaseContract.prototype.waitForDeployment === "function".const address = signer.getAddress()→typeof address === "object",address instanceof Promise === true; withawait→typeof === "string".Note
Low Risk
Documentation-only edits to example snippets; no runtime or product code paths change.
Overview
Repairs the ethers.js deploy contract example in
_ethereum-integration-snippets.mdxso it matches ethers v6 and parses as valid JavaScript.The broken
ContractFactory(JSON.parse(JSON.stringify(contractABI), contractByteCode, address)call (unbalanced parentheses and wrong arguments) is replaced withnew ContractFactory(contractABI, contractByteCode, signer). Post-deploy steps usewaitForDeployment()andawait contract.getAddress()instead of the v5deployed()/receipt.contractAddresspattern. The unusedsigner.getAddress()line tied to that mistake is removed.Reviewed by Cursor Bugbot for commit ca97a02. Bugbot is set up for automated code reviews on this repo. Configure here.