Skip to content

docs(embedded-wallets): fix broken EVM snippets in integration guide - #3058

Open
callumweb3 wants to merge 1 commit into
MetaMask:mainfrom
callumweb3:patch-1
Open

callumweb3 wants to merge 1 commit into
MetaMask:mainfrom
callumweb3:patch-1

Conversation

@callumweb3

@callumweb3 callumweb3 commented Sep 16, 2026

Copy link
Copy Markdown

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

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 #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:
image
  • typeof ethers.Contract.prototype.deployed === "undefined", typeof ethers.BaseContract.prototype.waitForDeployment === "function".
  • const address = signer.getAddress()typeof address === "object", address instanceof Promise === true; with awaittypeof === "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.mdx so 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 with new ContractFactory(contractABI, contractByteCode, signer). Post-deploy steps use waitForDeployment() and await contract.getAddress() instead of the v5 deployed() / receipt.contractAddress pattern. The unused signer.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.

## 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
callumweb3 requested review from a team as code owners September 16, 2026 13:03
@vercel

vercel Bot commented Sep 16, 2026

Copy link
Copy Markdown

@callumweb3 is attempting to deploy a commit to the Consensys Team on Vercel.

A member of the Team first needs to authorize it.

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.

Docs we want to add

1 participant