Skip to content

Fix: Replace deprecated connect() in useScaffoldContract hook#337

Open
Einarmig wants to merge 56 commits intoScaffold-Stark:base-challenge-templatefrom
Einarmig:fix/contract-connect-error
Open

Fix: Replace deprecated connect() in useScaffoldContract hook#337
Einarmig wants to merge 56 commits intoScaffold-Stark:base-challenge-templatefrom
Einarmig:fix/contract-connect-error

Conversation

@Einarmig
Copy link
Copy Markdown

@Einarmig Einarmig commented Oct 25, 2025

Fix: Contract Connection Error in useScaffoldContract Hook

Problem

The application was crashing when users connected their wallet and navigated to the "My NFTs" section with the following error:

Error: contractInstance.connect is not a function

Error Location: hooks/scaffold-stark/useScaffoldContract.ts:43

Root Cause

The useScaffoldContract hook was using the deprecated .connect() method from starknet.js v6.x API, which no longer exists in starknet.js v8.x.

Old Code (Broken)

const contractInstance = new Contract({
  abi: deployedContractData.abi as Abi,
  address: deployedContractData.address,
  providerOrAccount: publicClient,
});

if (account) {
  contractInstance.connect(account); // ❌ This method doesn't exist in v8
}

Solution

Updated the contract instantiation to use the new starknet.js v8 API, where the account is passed directly in the constructor instead of using a separate .connect() call.

New Code (Fixed)

const contractInstance = new Contract({
  abi: deployedContractData.abi as Abi,
  address: deployedContractData.address,
  providerOrAccount: account || publicClient, // ✅ Pass account directly
});

Impact

  • ✅ Users can now connect their wallet and access "My NFTs" without crashes
  • ✅ Contract instances properly use the connected account when available
  • ✅ Falls back to read-only provider when no wallet is connected
  • ✅ Compatible with starknet.js v8.5.3

Files Changed

  • packages/nextjs/hooks/scaffold-stark/useScaffoldContract.ts

Testing

  1. Connect wallet to the application
  2. Navigate to "My NFTs" section
  3. Verify no runtime errors occur
  4. Verify NFTs load correctly

Types of change

  • Bug

gianalarcon and others added 30 commits August 15, 2024 18:00
Co-authored-by: Nadai2010 <nadai2010@proton.me>
…#165)

Co-authored-by: metalboyrick <rsulisthio@gmail.com>
…tark#175) [skip ci]

Co-authored-by: Nadai <112663528+Nadai2010@users.noreply.github.com>
Co-authored-by: Bủ <57097047+Buuh2511@users.noreply.github.com>
Co-authored-by: AMD <90222287+michojekunle@users.noreply.github.com>
Co-authored-by: GianMarco <gian@quantum3labs.com>
Co-authored-by: tu11aa <thanhtuhr01@gmail.com>
gianalarcon and others added 26 commits May 5, 2025 22:09
Co-authored-by: gianmalarcon <gian@quantum3labs.com>
Co-authored-by: gianmalarcon <gian@quantum3labs.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: truthixify <124162045+truthixify@users.noreply.github.com>
…eScaffoldContract

  - Fixes runtime error when connecting wallet and accessing My NFTs
  - Updates to starknet.js v8 API (account in constructor instead of .connect())
  - Maintains backward compatibility with read-only mode
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.