From d45b91b92e66e576df8214ae5c649f5f18fab12a Mon Sep 17 00:00:00 2001 From: nishantxscooby Date: Sat, 10 Jan 2026 01:29:43 +0530 Subject: [PATCH 1/2] Migrate DJED SDK from Web3.js to Ethers.js (fixes #10) --- stablepay-sdk/package.json | 3 +-- stablepay-sdk/rollup.config.mjs | 3 +-- stablepay-sdk/src/contexts/WalletContext.jsx | 2 +- stablepay-sdk/src/core/Transaction.js | 22 +++++++++++++------- stablepay-sdk/src/core/Wallet.js | 2 +- 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/stablepay-sdk/package.json b/stablepay-sdk/package.json index 6b4f884..873fbcc 100644 --- a/stablepay-sdk/package.json +++ b/stablepay-sdk/package.json @@ -15,8 +15,7 @@ "djed-sdk": "^1.0.2", "react": "^18.3.1", "react-dom": "^18.3.1", - "viem": "^2.21.53", - "web3": "^1.7.3" + "viem": "^2.21.53" }, "devDependencies": { "@babel/preset-react": "^7.25.7", diff --git a/stablepay-sdk/rollup.config.mjs b/stablepay-sdk/rollup.config.mjs index 57aa2ca..f4cd33f 100644 --- a/stablepay-sdk/rollup.config.mjs +++ b/stablepay-sdk/rollup.config.mjs @@ -19,7 +19,6 @@ export default { file: "dist/umd/index.js", globals: { "djed-sdk": "DjedSdk", - web3: "Web3", react: "React", "react-dom": "ReactDOM", viem: "viem", @@ -29,7 +28,7 @@ export default { assetFileNames: "assets/[name][extname]", }, ], - external: ["djed-sdk", "web3", "react", "react-dom", "viem", "viem/chains"], + external: ["djed-sdk", "react", "react-dom", "viem", "viem/chains"], plugins: [ resolve({ extensions: [".js", ".jsx"], diff --git a/stablepay-sdk/src/contexts/WalletContext.jsx b/stablepay-sdk/src/contexts/WalletContext.jsx index 3eff2b2..b6533b4 100644 --- a/stablepay-sdk/src/contexts/WalletContext.jsx +++ b/stablepay-sdk/src/contexts/WalletContext.jsx @@ -25,7 +25,7 @@ export const WalletProvider = ({ children }) => { const connectWallet = useCallback(async () => { if (!window.ethereum) { - setError('Please install MetaMask or another Web3 wallet'); + setError('Please install MetaMask or another Ethereum wallet'); return false; } diff --git a/stablepay-sdk/src/core/Transaction.js b/stablepay-sdk/src/core/Transaction.js index 9a4d91b..041d7d9 100644 --- a/stablepay-sdk/src/core/Transaction.js +++ b/stablepay-sdk/src/core/Transaction.js @@ -12,9 +12,14 @@ export class Transaction { } try { - this.web3 = await getWeb3(this.networkUri); - this.djedContract = getDjedContract(this.web3, this.djedAddress); - const { stableCoin, reserveCoin } = await getCoinContracts(this.djedContract, this.web3); + // getWeb3 now returns {provider, signer} + const { provider, signer } = await getWeb3(this.networkUri); + this.provider = provider; + this.signer = signer; + + // Use signer for contract interactions (allows write operations) + this.djedContract = getDjedContract(this.signer, this.djedAddress); + const { stableCoin, reserveCoin } = await getCoinContracts(this.djedContract, this.signer); const { scDecimals, rcDecimals } = await getDecimals(stableCoin, reserveCoin); this.stableCoin = stableCoin; this.reserveCoin = reserveCoin; @@ -23,10 +28,10 @@ export class Transaction { // Get the oracle contract 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; console.log('Transaction initialized successfully'); } catch (error) { @@ -37,10 +42,11 @@ export class Transaction { getBlockchainDetails() { return { - web3Available: !!this.web3, + providerAvailable: !!this.provider, + signerAvailable: !!this.signer, djedContractAvailable: !!this.djedContract, - stableCoinAddress: this.stableCoin ? this.stableCoin._address : 'N/A', - reserveCoinAddress: this.reserveCoin ? this.reserveCoin._address : 'N/A', + stableCoinAddress: this.stableCoin ? this.stableCoin.target : 'N/A', + reserveCoinAddress: this.reserveCoin ? this.reserveCoin.target : 'N/A', stableCoinDecimals: this.scDecimals, reserveCoinDecimals: this.rcDecimals, oracleAddress: this.oracleAddress || 'N/A', diff --git a/stablepay-sdk/src/core/Wallet.js b/stablepay-sdk/src/core/Wallet.js index 0c666ef..31e32ba 100644 --- a/stablepay-sdk/src/core/Wallet.js +++ b/stablepay-sdk/src/core/Wallet.js @@ -7,7 +7,7 @@ export class Wallet { async connect() { if (!window.ethereum) { - throw new Error('No Web3 provider found'); + throw new Error('No Ethereum provider found'); } const accounts = await window.ethereum.request({ From e04f1880ad07b9bec81ce6ec45496dcf08591295 Mon Sep 17 00:00:00 2001 From: nishantxscooby Date: Sat, 10 Jan 2026 03:27:42 +0530 Subject: [PATCH 2/2] Update Blockscout URLs to new etc.blockscout.com interface (fixes #19) --- stablepay-sdk/src/contexts/WalletContext.jsx | 2 +- stablepay-sdk/src/contexts/chains.js | 2 +- stablepay-sdk/src/widget/TransactionReview.jsx | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/stablepay-sdk/src/contexts/WalletContext.jsx b/stablepay-sdk/src/contexts/WalletContext.jsx index b6533b4..11ea0df 100644 --- a/stablepay-sdk/src/contexts/WalletContext.jsx +++ b/stablepay-sdk/src/contexts/WalletContext.jsx @@ -65,7 +65,7 @@ export const WalletProvider = ({ children }) => { decimals: 18, }, rpcUrls: ['https://rpc.mordor.etccooperative.org'], - blockExplorerUrls: ['https://etc-mordor.blockscout.com/'], + blockExplorerUrls: ['https://etc.blockscout.com/mordor'], }, ], }); diff --git a/stablepay-sdk/src/contexts/chains.js b/stablepay-sdk/src/contexts/chains.js index 5722c56..fd3ed49 100644 --- a/stablepay-sdk/src/contexts/chains.js +++ b/stablepay-sdk/src/contexts/chains.js @@ -16,7 +16,7 @@ export const mordor = defineChain({ }, }, blockExplorers: { - default: { name: 'BlockScout', url: 'https://blockscout.com/etc/mordor' }, + default: { name: 'BlockScout', url: 'https://etc.blockscout.com/mordor' }, }, testnet: true, }); diff --git a/stablepay-sdk/src/widget/TransactionReview.jsx b/stablepay-sdk/src/widget/TransactionReview.jsx index e3ed29c..53d1133 100644 --- a/stablepay-sdk/src/widget/TransactionReview.jsx +++ b/stablepay-sdk/src/widget/TransactionReview.jsx @@ -187,7 +187,7 @@ const TransactionReview = ({ onTransactionComplete }) => { if (!txHash || !selectedNetwork) return null; const explorerBaseUrls = { - "ethereum-classic": "https://etc-mordor.blockscout.com/tx/", + "ethereum-classic": "https://etc.blockscout.com/mordor/tx/", "sepolia": "https://sepolia.etherscan.io/tx/", "milkomeda-mainnet": "https://explorer-mainnet-cardano-evm.c1.milkomeda.com/tx/", }; @@ -260,7 +260,7 @@ const TransactionReview = ({ onTransactionComplete }) => {
✅ Transaction Hash:{" "}