Skip to content

Fix: Replace Ethers.js sendTransaction with Web3.js implementation in…#91

Open
Rav1Chauhan wants to merge 2 commits intoDjedAlliance:mainfrom
Rav1Chauhan:fix/web3-promiseTx-consistency
Open

Fix: Replace Ethers.js sendTransaction with Web3.js implementation in…#91
Rav1Chauhan wants to merge 2 commits intoDjedAlliance:mainfrom
Rav1Chauhan:fix/web3-promiseTx-consistency

Conversation

@Rav1Chauhan
Copy link

@Rav1Chauhan Rav1Chauhan commented Feb 24, 2026

… promiseTx

Addressed Issues:

Fixes #68

Screenshots/Recordings:

Not applicable.

This change updates internal transaction handling logic in
djed-sdk/src/djed/tradeUtils.js and does not affect UI components.

The fix was verified by testing transaction submission using a standard Web3 provider.

Additional Notes:

🔍 Problem

The promiseTx helper used:

signer.sendTransaction(tx)

This is Ethers.js syntax, but the rest of the SDK consistently uses Web3.js contract objects and providers.

When using a Web3 provider, this resulted in:

sendTransaction is undefined

because Web3 providers do not expose sendTransaction in the same way as Ethers signers.

Checklist

  • [x ] My PR addresses a single issue, fixes a single bug or makes a single improvement.
  • [x ] My code follows the project's code style and conventions.
  • If applicable, I have made corresponding changes or additions to the documentation.
  • If applicable, I have made corresponding changes or additions to tests.
  • [ x] My changes generate no new warnings or errors.
  • [x ] I have joined the Stability Nexus's Discord server and I will share a link to this PR with the project maintainers there.
  • [x ] I have read the Contribution Guidelines.
  • [x ] Once I submit my PR, CodeRabbit AI will automatically review it and I will address CodeRabbit's comments.

⚠️ AI Notice - Important!

We encourage contributors to use AI tools responsibly when creating Pull Requests. While AI can be a valuable aid, it is essential to ensure that your contributions meet the task requirements, build successfully, include relevant tests, and pass all linters. Submissions that do not meet these standards may be closed without warning to maintain the quality and integrity of the project. Please take the time to understand the changes you are proposing and their impact.

Summary by CodeRabbit

  • Refactor
    • Transaction submission now uses a web3 provider for broader compatibility and improved handling.
  • Bug Fixes
    • Added validation to require a web3/eth provider and a transaction "from" address before sending.
    • Gas selection now falls back to sensible defaults when unspecified, preserving wallet-connection behavior and existing error propagation.
  • Style
    • Minor formatting tweaks for consistency.

@coderabbitai
Copy link

coderabbitai bot commented Feb 24, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f8c9cdd and 623a06d.

⛔ Files ignored due to path filters (2)
  • djed-sdk/dist/esm/index.js is excluded by !**/dist/**
  • djed-sdk/dist/umd/index.js is excluded by !**/dist/**
📒 Files selected for processing (1)
  • djed-sdk/src/djed/tradeUtils.js

📝 Walkthrough

Walkthrough

Updated the promiseTx helper to use Web3.js consistently: the third parameter changed from signer to web3, it validates web3/web3.eth and tx.from, and sends transactions via web3.eth.sendTransaction (gas fallback to 500000). Minor formatting tweaks retained.

Changes

Cohort / File(s) Summary
Transaction Library Standardization
djed-sdk/src/djed/tradeUtils.js
Changed promiseTx(isWalletConnected, tx, signer)promiseTx(isWalletConnected, tx, web3). Validates presence of web3 and web3.eth, requires tx.from. Replaced Ethers-style signer.sendTransaction(tx) with web3.eth.sendTransaction({ from, to, value, data, gas }) using `tx.gas

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • Zahnentferner

Poem

🐇 I nibbled code where two paths crossed,
Chose Web3’s trail — no syntax lost.
One hop, one call, transactions clear,
A tidy patch — I thump my ear. ✨

🚥 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 clearly reflects the main change: replacing Ethers.js sendTransaction with Web3.js implementation in promiseTx, which is the core fix described in the PR.
Linked Issues check ✅ Passed The PR successfully addresses issue #68 by replacing Ethers.js sendTransaction with Web3.js implementation, adding 'from' address validation, and ensuring Web3 provider compatibility as required.
Out of Scope Changes check ✅ Passed All changes are scoped to promiseTx implementation in tradeUtils.js to fix Web3.js/Ethers.js consistency; no unrelated modifications to other SDK components or UI elements are present.
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 unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@djed-sdk/src/djed/tradeUtils.js`:
- Around line 121-136: The promiseTx function should validate that tx.from is
present (reject with an Error if missing) and set the gas field using standard
Web3 naming and sensible precedence (use tx.gas if provided, else tx.gasLimit,
else 500000) when calling web3.eth.sendTransaction; update the sendTransaction
payload to include gas: selectedGas and keep other fields (from, to, value,
data) intact; also keep in mind web3.eth.sendTransaction returns a PromiEvent
(not an Ethers TransactionResponse) so callers relying on .hash/.wait() must be
adjusted accordingly.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 509e7d3 and 65fc40a.

📒 Files selected for processing (1)
  • djed-sdk/src/djed/tradeUtils.js

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

♻️ Duplicate comments (1)
djed-sdk/src/djed/tradeUtils.js (1)

136-147: ⚠️ Potential issue | 🟠 Major

Avoid wrapping sendTransaction in a plain Promise.

This strips the returned PromiEvent interface (transactionHash/confirmation listeners) and can regress existing transaction-lifecycle handling.

Suggested change
-  return new Promise((resolve, reject) => {
-    web3.eth
-      .sendTransaction({
-        from: tx.from,
-        to: tx.to,
-        value: tx.value,
-        data: tx.data,
-        gas: selectedGas,
-      })
-      .on("receipt", resolve)
-      .on("error", reject);
-  });
+  return web3.eth.sendTransaction({
+    from: tx.from,
+    to: tx.to,
+    value: tx.value,
+    data: tx.data,
+    gas: selectedGas,
+  });
#!/bin/bash
# Verify whether promiseTx consumers rely on tx-hash timing or PromiEvent methods.
rg -n -C3 --type js '\bpromiseTx\s*\(' djed-sdk/src
rg -n -C3 --type js '\.wait\s*\(|\.hash\b|transactionHash|\.on\(\s*["'\'']transactionHash["'\'']' djed-sdk/src
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@djed-sdk/src/djed/tradeUtils.js` around lines 136 - 147, The current
promiseTx implementation wraps web3.eth.sendTransaction in a plain Promise which
discards the PromiEvent API (transactionHash/confirmation listeners); update
promiseTx so it returns the original PromiEvent from web3.eth.sendTransaction
(or returns that PromiEvent after attaching .on('receipt', resolve) and
.on('error', reject) handlers) instead of a new Promise, preserving
transactionHash and confirmation listeners; locate the promiseTx function in
djed-sdk/src/djed/tradeUtils.js and change the return to pass through the
sendTransaction PromiEvent rather than wrapping it.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@djed-sdk/src/djed/tradeUtils.js`:
- Around line 121-147: The bundled distribution still contains the old
promiseTx(isWalletConnected, tx, signer) implementation; regenerate the compiled
bundle so djed-sdk/dist/esm/index.js reflects the updated promiseTx using
web3.eth.sendTransaction with event handlers (.on("receipt",
resolve).on("error", reject)). Rebuild the package (run the project’s build
script or transpiler) to produce a new dist, verify that the exported promiseTx
in djed-sdk/dist/esm/index.js matches the source implementation (checks for
web3.eth and selectedGas logic and the .on handlers), and commit the regenerated
dist alongside the source change.

---

Duplicate comments:
In `@djed-sdk/src/djed/tradeUtils.js`:
- Around line 136-147: The current promiseTx implementation wraps
web3.eth.sendTransaction in a plain Promise which discards the PromiEvent API
(transactionHash/confirmation listeners); update promiseTx so it returns the
original PromiEvent from web3.eth.sendTransaction (or returns that PromiEvent
after attaching .on('receipt', resolve) and .on('error', reject) handlers)
instead of a new Promise, preserving transactionHash and confirmation listeners;
locate the promiseTx function in djed-sdk/src/djed/tradeUtils.js and change the
return to pass through the sendTransaction PromiEvent rather than wrapping it.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 65fc40a and f8c9cdd.

📒 Files selected for processing (1)
  • djed-sdk/src/djed/tradeUtils.js

@Rav1Chauhan Rav1Chauhan force-pushed the fix/web3-promiseTx-consistency branch from f8c9cdd to 623a06d Compare March 3, 2026 12:49
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.

[BUG] Mixing Web3.js and Ethers.js syntax

1 participant