iso-filecoin
Version:
Isomorphic filecoin abstractions for RPC, signatures, address, token and wallet
265 lines • 12 kB
TypeScript
/**
* Check if a value is a RpcError
*
* @param {unknown} value
* @returns {value is RpcError}
*/
export function isRpcError(value: unknown): value is RpcError;
export class RpcError extends Error {
/**
* Check if a value is a RequestError
*
* @param {unknown} value
* @returns {value is RpcError}
*/
static is(value: unknown): value is RpcError;
/**
*
* @param {string} message
* @param {ErrorOptions} [options]
*/
constructor(message: string, options?: ErrorOptions);
/** @type {unknown} */
cause: unknown;
/** @type {boolean} */
[symbol]: boolean;
}
export class JsonRpcError extends RpcError {
/**
* Check if a value is a JsonRpcError
*
* @param {unknown} value
* @returns {value is JsonRpcError}
*/
static is(value: unknown): value is JsonRpcError;
/**
*
* @param {import('./types.js').JsonRpcError} cause
*/
constructor(cause: import("./types.js").JsonRpcError);
/** @type {import('./types.js').JsonRpcError} */
cause: import("./types.js").JsonRpcError;
}
export class ValidationRpcError extends RpcError {
/**
* Check if a value is a ValidationRpcError
*
* @param {unknown} value
* @returns {value is ValidationRpcError}
*/
static is(value: unknown): value is ValidationRpcError;
/**
*
* @param {import('zod/v4').ZodError} cause
*/
constructor(cause: import("zod/v4").ZodError);
/** @type {import('zod/v4').ZodError} */
cause: import("zod/v4").ZodError;
}
/**
* RPC
*/
export class RPC {
/**
*
* TODO: remove fetch from Options and use fetch from RequestOptions
* TODO: either remove token or merge this.headers with fetchOptions.headers
*
* @param {Options} options
* @param {RequestOptions} [fetchOptions]
*/
constructor({ api, token, network, fetch, }: Options, fetchOptions?: RequestOptions);
fetch: typeof fetch;
api: URL;
network: import("./types.js").Network;
headers: {
Authorization?: string | undefined;
'Content-Type': string;
};
fetchOptions: import("iso-web/types").RequestOptions;
/**
* Version returns the version of the Filecoin node.
*
* @param {RequestOptions} [fetchOptions]
*/
version(fetchOptions?: RequestOptions): Promise<MaybeResult<VersionResponse, RequestErrors | JsonRpcError>>;
/**
* NetworkName returns the name of the network the node is synced to.
*
* @param {RequestOptions} [fetchOptions]
*/
networkName(fetchOptions?: RequestOptions): Promise<MaybeResult<import("./types.js").Network, RequestErrors | JsonRpcError>>;
/**
* GasEstimateMessageGas estimates gas values for unset message gas fields
*
* @see https://lotus.filecoin.io/reference/lotus/gas/#gasestimatemessagegas
*
* @param {GasEstimateParams} params
* @param {RequestOptions} [fetchOptions]
* @return {Promise<MaybeResult<GasEstimateMessageGasResponse, RequestErrors | JsonRpcError | RpcError | ValidationRpcError>>}
*/
gasEstimate(params: GasEstimateParams, fetchOptions?: RequestOptions): Promise<MaybeResult<GasEstimateMessageGasResponse, RequestErrors | JsonRpcError | RpcError | ValidationRpcError>>;
/**
* WalletBalance returns the balance of the given address at the current head of the chain.
*
* @see https://lotus.filecoin.io/reference/lotus/wallet/#walletbalance
*
* @param {string} address
* @param {RequestOptions} [fetchOptions]
* @returns {Promise<MaybeResult<WalletBalanceResponse, RequestErrors | JsonRpcError | RpcError>>}
*/
balance(address: string, fetchOptions?: RequestOptions): Promise<MaybeResult<WalletBalanceResponse, RequestErrors | JsonRpcError | RpcError>>;
/**
* MpoolGetNonce gets next nonce for the specified sender. Note that this method may not be atomic. Use MpoolPushMessage instead.
*
* @see https://lotus.filecoin.io/reference/lotus/mpool/#mpoolgetnonce
* @param {string} address
* @param {RequestOptions} [fetchOptions]
* @returns {Promise<MaybeResult<MpoolGetNonceResponse, RequestErrors | JsonRpcError | RpcError>>}
*/
nonce(address: string, fetchOptions?: RequestOptions): Promise<MaybeResult<MpoolGetNonceResponse, RequestErrors | JsonRpcError | RpcError>>;
/**
* MpoolPush pushes a signed message to mempool.
*
* @see https://lotus.filecoin.io/reference/lotus/mpool/#mpoolpush
*
* @param {PushMessageParams} params
* @param {RequestOptions} [fetchOptions]
* @returns {Promise<MaybeResult<MpoolPushResponse, RequestErrors | JsonRpcError | RpcError | ValidationRpcError>>}
*/
pushMessage(params: PushMessageParams, fetchOptions?: RequestOptions): Promise<MaybeResult<MpoolPushResponse, RequestErrors | JsonRpcError | RpcError | ValidationRpcError>>;
/**
* StateWaitMsg looks back in the chain for a message. If not found, it blocks until the message arrives on chain, and gets to the indicated confidence depth.
*
* Timeout is increased to 60s instead of the default 5s.
*
* @see https://lotus.filecoin.io/reference/lotus/state/#statewaitmsg
* @param {waitMsgParams} params
* @param {RequestOptions} [fetchOptions]
* @returns {Promise<MaybeResult<MpoolPushResponse, RequestErrors | JsonRpcError>>}
*/
waitMsg(params: waitMsgParams, fetchOptions?: RequestOptions): Promise<MaybeResult<MpoolPushResponse, RequestErrors | JsonRpcError>>;
/**
* Converts any Filecoin address to an EthAddress.
*
* @see https://github.com/filecoin-project/lotus/blob/471819bf1ef8a4d5c7c0476a38ce9f5e23c59bfc/api/api_full.go#L743-L768
* @param {FilecoinAddressToEthAddressParams} params
* @param {RequestOptions} [fetchOptions]
* @returns {Promise<MaybeResult<string, RequestErrors | JsonRpcError | RpcError>>}
*/
filecoinAddressToEthAddress(params: FilecoinAddressToEthAddressParams, fetchOptions?: RequestOptions): Promise<MaybeResult<string, RequestErrors | JsonRpcError | RpcError>>;
/**
* Public key address of the given ID address.
*
* @see https://github.com/filecoin-project/lotus/blob/master/documentation/en/api-v0-methods.md#StateAccountKey
*
*
* @param {StateAccountKeyParams} params
* @param {RequestOptions} [fetchOptions]
* @returns {Promise<MaybeResult<string, RequestErrors | JsonRpcError | RpcError>>}
*/
stateAccountKey(params: StateAccountKeyParams, fetchOptions?: RequestOptions): Promise<MaybeResult<string, RequestErrors | JsonRpcError | RpcError>>;
/**
* Public key address of the given non-account ID address.
*
* @see https://github.com/filecoin-project/lotus/blob/master/documentation/en/api-v0-methods.md#StateLookupRobustAddress
*
*
* @param {StateAccountKeyParams} params
* @param {RequestOptions} [fetchOptions]
* @returns {Promise<MaybeResult<string, RequestErrors | JsonRpcError | RpcError>>}
*/
stateLookupRobustAddress(params: StateAccountKeyParams, fetchOptions?: RequestOptions): Promise<MaybeResult<string, RequestErrors | JsonRpcError | RpcError>>;
/**
* Retrieves the ID address of the given address for a tipset.
* If you dont have a specific tipset in mind, better to use {@link getIDAddress}.
*
* @see https://github.com/filecoin-project/lotus/blob/master/documentation/en/api-v0-methods.md#statelookupid
*
*
* @param {StateAccountKeyParams} params
* @param {RequestOptions} [fetchOptions]
* @returns {Promise<MaybeResult<string, RequestErrors | JsonRpcError >>}
*/
stateLookupID(params: StateAccountKeyParams, fetchOptions?: RequestOptions): Promise<MaybeResult<string, RequestErrors | JsonRpcError>>;
/**
* The current head of the chain.
*
* @see https://github.com/filecoin-project/filecoin-docs/blob/main/reference/json-rpc/chain.md#chainhead
*
*
* @param {RequestOptions} [fetchOptions]
* @returns {Promise<MaybeResult<TipSet, RequestErrors | JsonRpcError >>}
*/
chainHead(fetchOptions?: RequestOptions): Promise<MaybeResult<TipSet, RequestErrors | JsonRpcError>>;
/**
* Get tipset at the specified epoch (height). If there are no blocks at the specified epoch, a tipset at an earlier epoch will be returned.
*
* @see https://github.com/filecoin-project/filecoin-docs/blob/main/reference/json-rpc/chain.md#chaingettipsetbyheight
*
* @param {ChainGetTipSetByHeightParams} params
* @param {RequestOptions} [fetchOptions]
* @returns {Promise<MaybeResult<TipSet, RequestErrors | JsonRpcError >>}
*/
getTipSetByHeight(params: ChainGetTipSetByHeightParams, fetchOptions?: RequestOptions): Promise<MaybeResult<TipSet, RequestErrors | JsonRpcError>>;
/**
* Looks back from latest height for a tipset
*
* @param {number} lookback - Chain epoch to look back to
* @param {RequestOptions} [fetchOptions]
* @returns {Promise<MaybeResult<TipSet, RequestErrors | JsonRpcError | RpcError>>}
*/
lookBackTipSet(lookback: number, fetchOptions?: RequestOptions): Promise<MaybeResult<TipSet, RequestErrors | JsonRpcError | RpcError>>;
/**
* Get the ID address for an address with different safety guarantees
*
* @param {{address: string, safety?: Safety}} params
* @param {RequestOptions} [fetchOptions]
* @returns {Promise<MaybeResult<string, RequestErrors | JsonRpcError | RpcError>>}
*/
getIDAddress(params: {
address: string;
safety?: Safety;
}, fetchOptions?: RequestOptions): Promise<MaybeResult<string, RequestErrors | JsonRpcError | RpcError>>;
/**
* Generic method to call any method on the lotus rpc api.
*
* @template R
* @param {RpcOptions} rpcOptions
* @param {RequestOptions} [fetchOptions]
* @returns {Promise<MaybeResult<R, RequestErrors | JsonRpcError>>}
*/
call<R>(rpcOptions: RpcOptions, fetchOptions?: RequestOptions): Promise<MaybeResult<R, RequestErrors | JsonRpcError>>;
#private;
}
export type RequestOptions = import("iso-web/types").RequestOptions;
export type RequestErrors = import("iso-web/http").Errors | import("iso-web/http").JsonError;
/**
* @import {ChainGetTipSetByHeightParams, FilecoinAddressToEthAddressParams, GasEstimateMessageGasResponse, GasEstimateParams, JsonRpcResponse, MaybeResult, MpoolGetNonceResponse, MpoolPushResponse, Options, PushMessageParams, RpcOptions, Safety, StateAccountKeyParams, StateNetworkNameResponse, TipSet, VersionResponse, waitMsgParams, WalletBalanceResponse} from './types.js'
*/
/**
* @typedef {import('iso-web/types').RequestOptions} RequestOptions
* @typedef {import('iso-web/http').Errors | import('iso-web/http').JsonError} RequestErrors
*/
/**
* Error symbol
*/
declare const symbol: unique symbol;
import type { VersionResponse } from './types.js';
import type { MaybeResult } from './types.js';
import type { GasEstimateParams } from './types.js';
import type { GasEstimateMessageGasResponse } from './types.js';
import type { WalletBalanceResponse } from './types.js';
import type { MpoolGetNonceResponse } from './types.js';
import type { PushMessageParams } from './types.js';
import type { MpoolPushResponse } from './types.js';
import type { waitMsgParams } from './types.js';
import type { FilecoinAddressToEthAddressParams } from './types.js';
import type { StateAccountKeyParams } from './types.js';
import type { TipSet } from './types.js';
import type { ChainGetTipSetByHeightParams } from './types.js';
import type { Safety } from './types.js';
import type { RpcOptions } from './types.js';
import type { Options } from './types.js';
export { AbortError, HttpError, JsonError, NetworkError, RequestError, TimeoutError } from "iso-web/http";
//# sourceMappingURL=rpc.d.ts.map