-
-
Notifications
You must be signed in to change notification settings - Fork 22
refactor: migrate from Web3.js to Ethers.js #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,19 @@ | ||
| // Call contract read method using ethers | ||
| export function web3Promise(contract, method, ...args) { | ||
| return contract.methods[method](...args).call(); | ||
| return contract[method](...args); | ||
| } | ||
| // Function to build a transaction | ||
|
|
||
| // Function to build a transaction object for ethers signer | ||
| // Set gas limit to 500,000 by default | ||
| export function buildTx(from_, to_, value_, data_, setGasLimit = true) { | ||
| const tx = { | ||
| to: to_, | ||
| from: from_, | ||
| value: "0x" + BigInt(value_).toString(16), // Use BigInt instead of BN | ||
| value: value_ ? BigInt(value_) : 0n, | ||
| data: data_, | ||
| }; | ||
| if (setGasLimit) { | ||
| tx.gasLimit = 500_000; | ||
| tx.gasLimit = 500_000n; | ||
| } | ||
| return tx; | ||
|
Comment on lines
8
to
18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Check if dist files contain outdated BigInt hex conversion patterns
echo "=== Checking dist/esm/index.js ==="
rg -n "0x.*BigInt.*toString\(16\)" djed-sdk/dist/esm/index.js || echo "Pattern not found"
echo ""
echo "=== Checking dist/umd/index.js ==="
rg -n "0x.*BigInt.*toString\(16\)" djed-sdk/dist/umd/index.js || echo "Pattern not found"
echo ""
echo "=== Checking if source uses direct BigInt ==="
rg -n "value_.*BigInt.*:" djed-sdk/src/helpers.jsRepository: DjedAlliance/StablePay Length of output: 385 Rebuild dist files to reflect the updated source code. The source code uses direct BigInt values ( 🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,16 @@ | ||
| import { convertInt,web3Promise } from "../helpers"; | ||
| import { ethers } from "ethers"; | ||
| import { convertInt, web3Promise } from "../helpers"; | ||
| import oracleArtifact from "../artifacts/OracleABI.json"; | ||
|
|
||
| export const getOracleAddress = async (djedContract) => { | ||
| return await web3Promise(djedContract, "oracle"); | ||
| }; | ||
|
|
||
| export const getOracleContract = (web3, oracleAddress, msgSender) => { | ||
| const oracle = new web3.eth.Contract(oracleArtifact.abi, oracleAddress, { | ||
| from: msgSender | ||
| }); | ||
| export const getOracleContract = (provider, oracleAddress) => { | ||
| const oracle = new ethers.Contract( | ||
| oracleAddress, | ||
| oracleArtifact.abi, | ||
| provider | ||
| ); | ||
| return oracle; | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: DjedAlliance/StablePay
Length of output: 118
🏁 Script executed:
Repository: DjedAlliance/StablePay
Length of output: 110
🏁 Script executed:
Repository: DjedAlliance/StablePay
Length of output: 75
🏁 Script executed:
grep -r "web3Promise" djed-sdk/src/ -A 5 -B 2Repository: DjedAlliance/StablePay
Length of output: 8867
🏁 Script executed:
Repository: DjedAlliance/StablePay
Length of output: 608
🏁 Script executed:
cat djed-sdk/src/djed/djed.js | head -20Repository: DjedAlliance/StablePay
Length of output: 814
Add
ethersas a dependency inpackage.json.The file imports
ethersbut the package is not listed indjed-sdk/package.json. Specify the ethers version in dependencies (or devDependencies) to resolve the missing module error at runtime. Confirm the version aligns with the API patterns used (e.g.,new ethers.Contract(address, abi, provider)).🤖 Prompt for AI Agents