Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nockbox/iris-sdk",
"version": "0.2.0",
"version": "0.3.0",
"description": "TypeScript SDK for interacting with Iris wallet extension",
"type": "module",
"main": "./dist/index.js",
Expand Down
3 changes: 3 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export const PROVIDER_METHODS = {

/** Sign a nockchain transaction */
SIGN_TX: 'nock_signTx',

/** Estimate the network fee for a simple send (read-only, no approval popup) */
ESTIMATE_TRANSACTION_FEE: 'nock_estimateTransactionFee',
} as const;

export type ProviderMethod = (typeof PROVIDER_METHODS)[keyof typeof PROVIDER_METHODS];
Expand Down
33 changes: 33 additions & 0 deletions src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import type {
SignMessageResponse,
ConnectRequest,
SendTransactionRequest,
EstimateTransactionFeeRequest,
EstimateTransactionFeeResponse,
} from './types.js';
import { WalletNotInstalledError, UserRejectedError, RpcError, NoAccountError } from './errors.js';
import { PROVIDER_METHODS, RPC_API_VERSION } from './constants.js';
Expand Down Expand Up @@ -134,6 +136,37 @@ export class NockchainProvider {
});
}

/**
* Estimate the network fee for a simple send without sending it.
* Read-only: requires an approved origin and unlocked wallet, but shows no approval popup.
* Requires API 1 (`nock_estimateTransactionFee` is not available on legacy API 0 wallets).
*
* The estimate is advisory: it depends on the wallet's current UTXO set and may
* drift slightly between estimation and an actual send.
*
* @param request - Recipient and amount in nicks
* @returns Promise resolving to the estimated fee in nicks
* @throws {NoAccountError} If no account is connected
* @throws {RpcError} If the RPC call fails (e.g. wallet locked, no UTXOs)
*
* @example
* ```typescript
* const { fee } = await provider.estimateTransactionFee({ to: recipient, amount });
* ```
*/
async estimateTransactionFee(
request: EstimateTransactionFeeRequest
): Promise<EstimateTransactionFeeResponse> {
if (!this.isConnected) {
throw new NoAccountError();
}

return this.request<EstimateTransactionFeeRequest, EstimateTransactionFeeResponse>({
method: PROVIDER_METHODS.ESTIMATE_TRANSACTION_FEE,
params: request,
});
}

/**
* Sign an arbitrary message with the current account
* @param message - The message to sign
Expand Down
19 changes: 18 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,27 @@ export interface SendTransactionRequest {
to: Address;
/** Amount to send in nicks (legacy number + canonical string/bigint accepted) */
amount: Nicks;
/** Transaction fee in nicks (legacy number + canonical string/bigint accepted) */
/**
* Transaction fee in nicks (legacy number + canonical string/bigint accepted).
* Optional: when omitted, the wallet estimates the fee, shows it in the approval
* popup, and auto-calculates the exact fee at build time. The send response
* reports the actual fee used.
*/
fee?: Nicks;
}

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;
}
Comment thread
thomas-kroes marked this conversation as resolved.

export interface EstimateTransactionFeeResponse {
/** Estimated fee in nicks (canonical string) */
fee: Nicks;
}

export interface SignTxRequest {
tx: NockchainTx;
/**
Expand Down
Loading