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({