Migrate DJED SDK from Web3.js to Ethers.js#34
Migrate DJED SDK from Web3.js to Ethers.js#34nishantxscooby wants to merge 1 commit intoDjedAlliance:mainfrom
Conversation
📝 WalkthroughWalkthroughThe 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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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. Comment |
There was a problem hiding this comment.
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
._addressproperty, 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:
- Updating djed-sdk to provide an ethers v6-compatible API, or
- 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:
web3Availableremoved and replaced withproviderAvailable+ newsignerAvailablefield- Address properties changed from
._addressto.target(Ethers.js migration)- New field
oracleContractAvailableaddedAny external consumers depending on the old field names will experience failures. Ensure:
- Breaking change is documented in a migration guide
- Version bump reflects this (major version per semver if not already done)
- 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
📒 Files selected for processing (5)
stablepay-sdk/package.jsonstablepay-sdk/rollup.config.mjsstablepay-sdk/src/contexts/WalletContext.jsxstablepay-sdk/src/core/Transaction.jsstablepay-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.
| 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; |
There was a problem hiding this comment.
🧩 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 -20Repository: DjedAlliance/StablePay
Length of output: 118
🏁 Script executed:
cat -n package.jsonRepository: DjedAlliance/StablePay
Length of output: 110
🏁 Script executed:
cat -n ./djed-sdk/package.jsonRepository: DjedAlliance/StablePay
Length of output: 762
🏁 Script executed:
cat -n ./stablepay-sdk/package.jsonRepository: DjedAlliance/StablePay
Length of output: 1298
🏁 Script executed:
grep -A 10 -B 2 "this.oracleContract\|this.djedContract" stablepay-sdk/src/core/Transaction.js | head -40Repository: DjedAlliance/StablePay
Length of output: 1578
🏁 Script executed:
find . -name "package-lock.json" -o -name "yarn.lock" | head -5Repository: DjedAlliance/StablePay
Length of output: 128
🏁 Script executed:
grep -r "from.*['\"]ethers['\"]" djed-sdk/src --include="*.js" --include="*.ts" | head -20Repository: DjedAlliance/StablePay
Length of output: 48
🏁 Script executed:
grep -r "require.*ethers" djed-sdk/src --include="*.js" --include="*.ts" | head -20Repository: DjedAlliance/StablePay
Length of output: 48
🏁 Script executed:
grep -A 5 '"ethers"' djed-sdk/package-lock.json | head -20Repository: DjedAlliance/StablePay
Length of output: 48
🏁 Script executed:
grep -A 5 '"ethers"' stablepay-sdk/package-lock.json | head -20Repository: DjedAlliance/StablePay
Length of output: 48
🏁 Script executed:
head -50 stablepay-sdk/src/core/Transaction.jsRepository: DjedAlliance/StablePay
Length of output: 1964
🏁 Script executed:
find ./djed-sdk/src -type f -name "*.js" -o -name "*.ts" | head -10Repository: DjedAlliance/StablePay
Length of output: 364
🏁 Script executed:
rg "getDjedContract|getOracleContract" djed-sdk/src --type js --type ts -A 10 | head -60Repository: 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.jsRepository: 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.targetwill beundefined, causinggetOracleContractto receive invalid input - Line 34:
this.oracleAddress = this.oracleContract.targetwill beundefined - Lines 48–49:
this.stableCoin.targetandthis.reserveCoin.targetwill beundefined
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.
This PR fully migrates the DJED and StablePay SDKs from Web3.js to Ethers.js v6.
Highlights:
Compatibility:
{ provider, signer } instead of a Web3 instance.
Build validation:
npx rollup -c.(
@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
Refactor
Bug Fixes
✏️ Tip: You can customize this high-level summary in your review settings.