Web3 module to interact with the Ethereum blockchain and smart contracts.
67
Build a small module that constructs and manages an Ethereum RPC context, letting callers start from either an endpoint string or a provider object. The context should own default block/format settings and expose both instance methods and standalone helpers that all reuse the same underlying provider.
currentBlockHeight() to 12 when the mocked node reports block 12 and the default return format is "number". @test{ defaultBlock: "pending", returnFormat: "hex" }, calling accountBalance() returns the mocked pending balance "0xde0b6b3a7640000" (1 ether in wei). @testcurrentBlockHeight() on the context and rpcHelpers().blockHeight() should reuse the same underlying provider (a call counter reaches 2) and produce identical values when the provider increments responses per call. @testsetDefaults({ returnFormat: "hex" }) causes subsequent chainIdentifier() calls to return the mocked hex chain id "0x1" without recreating the provider. @test@generates
export interface ProviderDefaults {
defaultBlock?: "latest" | "pending" | "earliest" | number | string;
returnFormat?: "number" | "hex";
}
export type RpcProvider = string | { send(method: string, params?: unknown[]): Promise<unknown> };
export interface ProviderContext {
currentBlockHeight(): Promise<string | number>;
accountBalance(address: string): Promise<string | number>;
chainIdentifier(): Promise<string | number>;
minerAddress(): Promise<string>;
setDefaults(defaults: ProviderDefaults): void;
rpcHelpers(): {
blockHeight(): Promise<string | number>;
chainIdentifier(): Promise<string | number>;
minerAddress(): Promise<string>;
};
}
export function createProviderContext(provider: RpcProvider, defaults?: ProviderDefaults): ProviderContext;Ethereum RPC client with configurable provider contexts and return formatting.
Install with Tessl CLI
npx tessl i tessl/npm-web3-ethdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10