Skip to content

Migrate DJED SDK from Web3.js to Ethers.js#34

Open
nishantxscooby wants to merge 1 commit intoDjedAlliance:mainfrom
nishantxscooby:migrate-web3-to-ethers
Open

Migrate DJED SDK from Web3.js to Ethers.js#34
nishantxscooby wants to merge 1 commit intoDjedAlliance:mainfrom
nishantxscooby:migrate-web3-to-ethers

Conversation

@nishantxscooby
Copy link

@nishantxscooby nishantxscooby commented Jan 9, 2026

This PR fully migrates the DJED and StablePay SDKs from Web3.js to Ethers.js v6.

Highlights:

  • Replaced Web3 providers with ethers BrowserProvider + signer pattern
  • Migrated all contract instantiations to ethers.Contract
  • Replaced encodeABI() with interface.encodeFunctionData()
  • Updated balance and receipt fetching to ethers provider APIs
  • Removed all Web3 dependencies from both SDKs
  • Updated documentation and error messages accordingly

Compatibility:

  • Public API functions preserved (getWeb3, web3Promise), but getWeb3 now returns
    { provider, signer } instead of a Web3 instance.

Build validation:

  • djed-sdk bundles successfully via npx rollup -c.
  • stablepay-sdk build currently fails on main because required rollup plugins
    (@rollup/plugin-node-resolve, @rollup/plugin-commonjs) are not listed as dependencies.
    Verified this is a pre-existing packaging issue unrelated to this PR.

Fixes #10

Summary by CodeRabbit

  • Chores

    • Removed web3 library dependency from stablepay-sdk, simplifying package dependencies
  • Refactor

    • Updated wallet provider integration to use provider-signer pattern for contract interactions
    • Modified blockchain details response structure with updated availability indicators
  • Bug Fixes

    • Clarified error messages when Ethereum provider is not detected

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 9, 2026

📝 Walkthrough

Walkthrough

The pull request removes the web3.js dependency from the stablepay-sdk, replacing it with a provider/signer pattern compatible with ethers.js/viem. Changes include removing web3 from package.json and build configuration, updating error messages from "Web3 wallet" to "Ethereum wallet," and refactoring Transaction.js to use separate provider and signer objects for blockchain interactions.

Changes

Cohort / File(s) Summary
Build & Dependency Configuration
stablepay-sdk/package.json, stablepay-sdk/rollup.config.mjs
Removed web3 from package dependencies and rollup external configuration; updated UMD globals mapping
Error Messages
stablepay-sdk/src/contexts/WalletContext.jsx, stablepay-sdk/src/core/Wallet.js
Updated error messages from "Web3 wallet" to "Ethereum wallet" terminology
Core Transaction Logic
stablepay-sdk/src/core/Transaction.js
Replaced single web3 instance with separate provider and signer properties; updated getBlockchainDetails() return shape (replaced web3Available with providerAvailable and signerAvailable, added oracleContractAvailable); changed contract address resolution from ._address to .target pattern; modified oracle contract initialization to use signer instead of web3

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • Zahnentferner

Poem

🐰 Web3 bids farewell, viem takes the stage,
Provider and signer, the modern age,
Contracts now dance with a lighter touch,
Migration complete—we're grateful so much!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main objective of the PR: migrating the SDK from Web3.js to Ethers.js, which is reflected throughout all file changes.
Linked Issues check ✅ Passed The PR successfully addresses all objectives from issue #10: Web3.js imports are removed, contract interactions use provider/signer pattern, backward compatibility is maintained, and dependency removals confirm the migration.
Out of Scope Changes check ✅ Passed All changes are directly related to the Web3.js to Ethers.js migration: dependency removals, build configuration updates, contract interaction refactoring, and error message updates to reflect the new provider paradigm.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
stablepay-sdk/package.json (1)

14-19: The djed-sdk v1.0.2 API is incompatible with the Transaction.js implementation and will cause runtime failures.

The code expects an ethers v6 provider/signer pattern, but djed-sdk v1.0.2 provides a Web3 v1.7.3 API. Specific incompatibilities:

  • getWeb3() returns a single Web3 instance, not {provider, signer} (line 16 destructuring will fail)
  • getDjedContract(web3, address) signature expects Web3 as first param, not a signer (line 21 call is wrong)
  • Contract objects use ._address property, not .target (lines 31, 34, 48-49 will be undefined)
  • getOracleContract(web3, address, msgSender) expects Web3, not a signer (line 31 call is wrong)

This must be resolved by either:

  1. Updating djed-sdk to provide an ethers v6-compatible API, or
  2. Refactoring Transaction.js to use the Web3 v1.7.3 API that djed-sdk v1.0.2 actually exports
stablepay-sdk/src/core/Transaction.js (1)

43-55: Breaking change in public API return value requires documentation and communication.

The getBlockchainDetails() method has breaking changes:

  • web3Available removed and replaced with providerAvailable + new signerAvailable field
  • Address properties changed from ._address to .target (Ethers.js migration)
  • New field oracleContractAvailable added

Any external consumers depending on the old field names will experience failures. Ensure:

  1. Breaking change is documented in a migration guide
  2. Version bump reflects this (major version per semver if not already done)
  3. Change is communicated to SDK consumers
🤖 Fix all issues with AI agents
In @stablepay-sdk/src/core/Transaction.js:
- Around line 30-34: Replace all uses of the ethers-style `.target` on web3.js
contract instances with the web3.js property `.options.address`; specifically
update the call that passes this.djedContract.target into getOracleContract to
pass this.djedContract.options.address, set this.oracleAddress =
this.oracleContract.options.address, and likewise change references
this.stableCoin.target and this.reserveCoin.target to
this.stableCoin.options.address and this.reserveCoin.options.address so valid
addresses are supplied.
🧹 Nitpick comments (1)
stablepay-sdk/src/core/Transaction.js (1)

82-82: Consider extracting hardcoded UI address to configuration.

The hardcoded UI address '0x0232556C83791b8291E9b23BfEa7d67405Bd9839' on line 82 should ideally be defined as a constant or configuration parameter for better maintainability and testability.

♻️ Extract to constant

At the top of the file:

+const DEFAULT_UI_ADDRESS = '0x0232556C83791b8291E9b23BfEa7d67405Bd9839';
+
 export class Transaction {

Then update the usage:

-      const UI = '0x0232556C83791b8291E9b23BfEa7d67405Bd9839';
+      const UI = DEFAULT_UI_ADDRESS;
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2a125cf and d45b91b.

📒 Files selected for processing (5)
  • stablepay-sdk/package.json
  • stablepay-sdk/rollup.config.mjs
  • stablepay-sdk/src/contexts/WalletContext.jsx
  • stablepay-sdk/src/core/Transaction.js
  • stablepay-sdk/src/core/Wallet.js
🔇 Additional comments (4)
stablepay-sdk/src/core/Transaction.js (1)

15-22: LGTM! Clean migration to provider/signer pattern.

The destructuring of getWeb3() into separate provider and signer objects is correct for the ethers.js pattern. Using the signer for contract instantiation ensures write operations are properly authorized.

stablepay-sdk/src/core/Wallet.js (1)

10-10: LGTM! Appropriate terminology update.

The error message update from "Web3 provider" to "Ethereum provider" makes the SDK more provider-agnostic and aligns with the migration away from Web3.js-specific terminology.

stablepay-sdk/src/contexts/WalletContext.jsx (1)

28-28: LGTM! Consistent terminology update.

The error message update from "Web3 wallet" to "Ethereum wallet" is consistent with the broader migration and makes the SDK provider-agnostic.

stablepay-sdk/rollup.config.mjs (1)

31-31: LGTM! Clean removal of web3 dependency.

The removal of "web3" from the external modules list correctly reflects the migration away from Web3.js. The remaining externals (djed-sdk, react, react-dom, viem, viem/chains) are appropriate for the new architecture.

Comment on lines 30 to +34
this.oracleContract = await getOracleAddress(this.djedContract).then((addr) =>
getOracleContract(this.web3, addr, this.djedContract._address)
getOracleContract(this.signer, addr, this.djedContract.target)
);

this.oracleAddress = this.oracleContract._address;
this.oracleAddress = this.oracleContract.target;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🌐 Web query:

ethers.js v6 .target property contract address

💡 Result:

In ethers v6 the Contract/BaseContract address field was renamed from .address to .target. .target can be an address/ENS name/Addressable; to get the resolved address use getAddress(). See the docs and migration notes. [1][2]

Example:

  • Reading the raw target (may be ENS or addressable):
    const addrOrName = myContract.target;
  • Getting the resolved address:
    const address = await myContract.getAddress();

Sources: [1] ethers v6 docs (BaseContract.target / getAddress). [2] v5→v6 migration notes (renamed address → target).


🏁 Script executed:

find . -name "package.json" -type f | head -20

Repository: DjedAlliance/StablePay

Length of output: 118


🏁 Script executed:

cat -n package.json

Repository: DjedAlliance/StablePay

Length of output: 110


🏁 Script executed:

cat -n ./djed-sdk/package.json

Repository: DjedAlliance/StablePay

Length of output: 762


🏁 Script executed:

cat -n ./stablepay-sdk/package.json

Repository: DjedAlliance/StablePay

Length of output: 1298


🏁 Script executed:

grep -A 10 -B 2 "this.oracleContract\|this.djedContract" stablepay-sdk/src/core/Transaction.js | head -40

Repository: DjedAlliance/StablePay

Length of output: 1578


🏁 Script executed:

find . -name "package-lock.json" -o -name "yarn.lock" | head -5

Repository: DjedAlliance/StablePay

Length of output: 128


🏁 Script executed:

grep -r "from.*['\"]ethers['\"]" djed-sdk/src --include="*.js" --include="*.ts" | head -20

Repository: DjedAlliance/StablePay

Length of output: 48


🏁 Script executed:

grep -r "require.*ethers" djed-sdk/src --include="*.js" --include="*.ts" | head -20

Repository: DjedAlliance/StablePay

Length of output: 48


🏁 Script executed:

grep -A 5 '"ethers"' djed-sdk/package-lock.json | head -20

Repository: DjedAlliance/StablePay

Length of output: 48


🏁 Script executed:

grep -A 5 '"ethers"' stablepay-sdk/package-lock.json | head -20

Repository: DjedAlliance/StablePay

Length of output: 48


🏁 Script executed:

head -50 stablepay-sdk/src/core/Transaction.js

Repository: DjedAlliance/StablePay

Length of output: 1964


🏁 Script executed:

find ./djed-sdk/src -type f -name "*.js" -o -name "*.ts" | head -10

Repository: DjedAlliance/StablePay

Length of output: 364


🏁 Script executed:

rg "getDjedContract|getOracleContract" djed-sdk/src --type js --type ts -A 10 | head -60

Repository: DjedAlliance/StablePay

Length of output: 1518


🌐 Web query:

web3.js contract address property how to access contract address web3.eth.Contract

💡 Result:

Use the contract instance's options.address property (stored lowercased). Example:

  • When creating:
    var myContract = new web3.eth.Contract(abi, '0xAbC...');

  • Read address:
    console.log(myContract.options.address); // '0xabc...'

  • Set or change address:
    myContract.options.address = '0x1234...';

(Note: older examples sometimes show contract._address, but the supported API is myContract.options.address.) [1][2]


🏁 Script executed:

head -20 djed-sdk/src/helpers.js

Repository: DjedAlliance/StablePay

Length of output: 622


🏁 Script executed:

cat -n stablepay-sdk/src/core/Transaction.js | sed -n '1,50p'

Repository: DjedAlliance/StablePay

Length of output: 2314


Replace .target with .options.address for web3.js contract instances.

The code uses .target to access contract addresses, but djed-sdk v1.0.2 bundles web3.js v1.7.3, not ethers.js v6. Web3.js contracts expose the address via the .options.address property, not .target. This affects:

  • Line 31: this.djedContract.target will be undefined, causing getOracleContract to receive invalid input
  • Line 34: this.oracleAddress = this.oracleContract.target will be undefined
  • Lines 48–49: this.stableCoin.target and this.reserveCoin.target will be undefined

Change all .target accesses to .options.address.

🤖 Prompt for AI Agents
In @stablepay-sdk/src/core/Transaction.js around lines 30 - 34, Replace all uses
of the ethers-style `.target` on web3.js contract instances with the web3.js
property `.options.address`; specifically update the call that passes
this.djedContract.target into getOracleContract to pass
this.djedContract.options.address, set this.oracleAddress =
this.oracleContract.options.address, and likewise change references
this.stableCoin.target and this.reserveCoin.target to
this.stableCoin.options.address and this.reserveCoin.options.address so valid
addresses are supplied.

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.

Migrate Djed SDK from Web3.js to Ethers.js

1 participant