Skip to content

Feat/public fee estimation#6

Open
thomas-kroes wants to merge 3 commits into
mainfrom
feat/public-fee-estimation
Open

Feat/public fee estimation#6
thomas-kroes wants to merge 3 commits into
mainfrom
feat/public-fee-estimation

Conversation

@thomas-kroes

Copy link
Copy Markdown

No description provided.

claude added 2 commits June 11, 2026 11:02
Adds a public, read-only provider method so dApps can query the
required network fee for a simple send without duplicating wallet/WASM
transaction-building logic:

- PROVIDER_METHODS.ESTIMATE_TRANSACTION_FEE ('nock_estimateTransactionFee')
- EstimateTransactionFeeRequest / EstimateTransactionFeeResponse types
- NockchainProvider.estimateTransactionFee({ to, amount }) -> { fee }
  (fee in nicks, canonical string)

Also documents the optional-fee semantics on SendTransactionRequest:
when fee is omitted the wallet estimates it for the approval popup,
auto-calculates the exact fee at build time, and reports the actual
fee used in the response.

The method is API 1-only; compat v0 mapping passes it through untouched
(default case), which is intentional.
@greptile-apps

greptile-apps Bot commented Jun 11, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds a public estimateTransactionFee method to NockchainProvider, exposing the nock_estimateTransactionFee RPC call as a read-only, no-popup way for dApps to preview the network fee before submitting a send. The change also makes fee optional on SendTransactionRequest so the wallet can auto-calculate it when omitted.

  • Adds ESTIMATE_TRANSACTION_FEE to PROVIDER_METHODS and EstimateTransactionFeeRequest/EstimateTransactionFeeResponse to src/types.ts, then wires them up with the new estimateTransactionFee method in src/provider.ts following the same guard-and-request pattern as sendTransaction and signTx.
  • Bumps the package version from 0.2.0 to 0.3.0, consistent with a new public API being added.

Confidence Score: 4/5

The change is a straightforward, additive feature with no modifications to existing logic; safe to merge.

The new method follows the same connect-guard → RPC-dispatch pattern as every other provider method and introduces no shared mutable state. The only thing worth a second look is a minor documentation inconsistency in the amount field comment on EstimateTransactionFeeRequest.

src/types.ts — the EstimateTransactionFeeRequest.amount JSDoc comment should match the more descriptive wording used on the same field in SendTransactionRequest.

Important Files Changed

Filename Overview
src/provider.ts Adds estimateTransactionFee method following the same guard-and-request pattern as sendTransaction and signTx; well-documented with JSDoc
src/types.ts Adds EstimateTransactionFeeRequest and EstimateTransactionFeeResponse interfaces; EstimateTransactionFeeRequest.amount comment is less descriptive than the parallel field in SendTransactionRequest
src/constants.ts Adds ESTIMATE_TRANSACTION_FEE constant to PROVIDER_METHODS; clean addition consistent with existing constants
package.json Version bump from 0.2.0 to 0.3.0 — appropriate for a new public API addition

Sequence Diagram

sequenceDiagram
    participant dApp
    participant NockchainProvider
    participant InjectedNockchain as window.nockchain

    dApp->>NockchainProvider: "estimateTransactionFee({ to, amount })"
    alt not connected
        NockchainProvider-->>dApp: throw NoAccountError
    else connected
        NockchainProvider->>InjectedNockchain: "request({ method: 'nock_estimateTransactionFee', params, api: '1.0.0' })"
        alt wallet locked / no UTXOs / API 0 wallet
            InjectedNockchain-->>NockchainProvider: RPC error
            NockchainProvider-->>dApp: throw RpcError
        else success
            InjectedNockchain-->>NockchainProvider: "EstimateTransactionFeeResponse { fee }"
            NockchainProvider-->>dApp: "EstimateTransactionFeeResponse { fee }"
        end
    end
Loading
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
src/types.ts:95-100
The `amount` field on `EstimateTransactionFeeRequest` omits the accepted-type note that appears on the parallel field in `SendTransactionRequest`. Since both fields carry the same `Nicks` type and the same runtime coercion rules apply, users consulting one interface but not the other may not know that legacy numbers and bigints are also accepted.

```suggestion
export interface EstimateTransactionFeeRequest {
  /** Recipient address (base58-encoded public key hash / PKH) */
  to: Address;
  /** Amount to send in nicks (legacy number + canonical string/bigint accepted) */
  amount: Nicks;
}
```

Reviews (1): Last reviewed commit: "chore: bump version to 0.3.0" | Re-trigger Greptile

Comment thread src/types.ts
Mirror the type-coercion note from SendTransactionRequest.amount so the
two parallel interfaces document the same accepted runtime types
(legacy number + canonical string/bigint).

Addresses review feedback on PR #6.
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.

2 participants