UNPKG

starknet-devnet

Version:
123 lines (122 loc) 5.04 kB
import { Postman } from "./postman"; import { Cheats } from "./cheats"; import { BalanceUnit, BlockId, PredeployedAccount } from "./types"; export type DevnetProviderConfig = { url?: string; /** milliseconds */ timeout?: number; }; export type MintResponse = { new_balance: bigint; unit: BalanceUnit; tx_hash: string; }; export interface NewBlockResponse { block_hash: string; } export interface AbortedBlocksResponse { aborted: Array<string>; } export interface SetTimeResponse { time: number; block_hash?: string; } export interface IncreaseTimeResponse { time: number; block_hash: string; } export interface GasModificationResponse { l1_gas_price?: bigint; l1_data_gas_price?: bigint; l2_gas_price?: bigint; } export declare class DevnetProvider { readonly url: string; private httpProvider; private rpcProvider; /** Contains methods for L1-L2 communication. */ readonly postman: Postman; /** Contains methods for cheating, e.g. account impersonation. */ readonly cheats: Cheats; constructor(config?: DevnetProviderConfig); /** * @returns `true` if the underlying Devnet instance is responsive; `false` otherwise */ isAlive(): Promise<boolean>; /** * Restart the state of the underlying Devnet instance. You may opt to restart L1-L2 messaging. * https://0xspaceshard.github.io/starknet-devnet/docs/dump-load-restart#restarting */ restart(params?: { restartL1ToL2Messaging?: boolean; }): Promise<void>; /** * Generate funds at the provided address. For return spec and more info, see * https://0xspaceshard.github.io/starknet-devnet/docs/balance#mint-token---local-faucet * @param address the account address to receive funds * @param amount how much to mint * @param unit specifier of the currency unit; defaults to FRI */ mint(address: string, amount: bigint, unit?: BalanceUnit): Promise<MintResponse>; /** * https://0xspaceshard.github.io/starknet-devnet/docs/predeployed#how-to-get-predeployment-info * @returns a list of containing information on predeployed accounts. Load an account using e.g. starknet.js. */ getPredeployedAccounts(additionalArgs?: { withBalance: boolean; }): Promise<Array<PredeployedAccount>>; /** * https://0xspaceshard.github.io/starknet-devnet/docs/blocks * @returns the block hash of the newly created block */ createBlock(): Promise<NewBlockResponse>; /** * https://0xspaceshard.github.io/starknet-devnet/docs/blocks * @param staringBlockId the block ID of the block after which (inclusive) all blocks * should be aborted. See docs {@link BlockId} for more info. * @returns hash values of aborted blocks */ abortBlocks(startingBlockId: BlockId): Promise<AbortedBlocksResponse>; /** * https://0xspaceshard.github.io/starknet-devnet/docs/next/starknet-time#set-time * @returns the new time in unix seconds and, if block creation requested, the hash of the created block */ setTime(time: number, additionalArgs?: { generateBlock: boolean; }): Promise<SetTimeResponse>; /** * Increase the time by the provided `increment` seconds. * https://0xspaceshard.github.io/starknet-devnet/docs/next/starknet-time#increase-time * @returns the new time in unix seconds */ increaseTime(increment: number): Promise<IncreaseTimeResponse>; /** * https://0xspaceshard.github.io/starknet-devnet/docs/dump-load-restart#dumping * @param path the path where your Devnet instance will be serialized; if not provided, defaults to the dump-path provided via CLI on Devnet startup. */ dump(path?: string): Promise<void>; /** * After loading, this DevnetProvider instance will be connected to the loaded Devnet instance. * https://0xspaceshard.github.io/starknet-devnet/docs/dump-load-restart#dumping * @param path the path from which a Devnet instance will be deserialized */ load(path: string): Promise<void>; /** * Modify gas prices, according to https://0xspaceshard.github.io/starknet-devnet/docs/gas * @param price new gas prices; any gas price can be ommitted * @param generateBlock if `true`, a new block is generated immediately, having new gas prices; * otherwise (by default) the price change takes effect with the usual next block generation * @returns gas prices after modification, including the unchanged ones */ setGasPrice(price: { l1GasPrice?: bigint; l1DataGasPrice?: bigint; l2GasPrice?: bigint; }, generateBlock?: boolean): Promise<GasModificationResponse>; /** * More info at: https://0xspaceshard.github.io/starknet-devnet/docs/api#config-api * @returns the configuration of the underlying Devnet instance. The returned object is marked * as `any` because it may change too often. */ getConfig(): Promise<any>; }