CtrlK
CommunityDocumentationLog inGet started
Tessl Logo

tessl/npm-walletconnect--types

tessl install tessl/npm-walletconnect--types@2.21.0

TypeScript type definitions and interfaces for the WalletConnect Protocol v2, enabling type-safe development across the WalletConnect ecosystem

Agent Success

Agent success rate when using this tile

70%

Improvement

Agent success rate improvement when using this tile compared to baseline

1.19x

Baseline

Agent success rate without this tile

59%

task.mdevals/scenario-1/

JSON-RPC Request Tracker

Build a request tracking system that manages JSON-RPC requests and responses, handling request correlation, timeout management, and pending request queries.

Requirements

Your system should:

  1. Store requests with metadata: When a JSON-RPC request is created, store it with a unique ID, topic, chain ID, and expiry timestamp.

  2. Update with responses: When a response arrives for a request, update the stored record to include the response data.

  3. Query pending requests: Provide the ability to query all pending requests (requests without responses) for a specific topic.

  4. Query by chain ID: Support querying all requests associated with a specific chain ID.

  5. Handle expiry: Automatically remove expired requests based on their expiry timestamps.

  6. Check request existence: Allow checking if a specific request ID exists in the history.

Implementation Details

Create a TypeScript module with the following:

  • A class or set of functions that manages request/response records
  • Each record should track: request ID, topic, chain ID, request data, response data (if received), and expiry timestamp
  • Methods to add requests, update with responses, query pending requests, query by chain ID, remove expired entries, and check existence

@generates

API

/**
 * Represents a stored JSON-RPC request/response record
 */
export interface RequestRecord {
  id: number;
  topic: string;
  chainId: string;
  request: {
    method: string;
    params: any;
  };
  response?: {
    result?: any;
    error?: any;
  };
  expiry: number;
}

/**
 * Manages JSON-RPC request/response history
 */
export class RequestTracker {
  /**
   * Add a new request to the tracker
   */
  set(topic: string, request: { id: number; chainId: string; request: { method: string; params: any }; expiry: number }): void;

  /**
   * Update a request with its response
   */
  resolve(id: number, response: { result?: any; error?: any }): void;

  /**
   * Get all pending requests for a topic (requests without responses)
   */
  getPending(topic: string): RequestRecord[];

  /**
   * Get all requests for a specific chain ID
   */
  getByChainId(chainId: string): RequestRecord[];

  /**
   * Remove all expired requests
   */
  removeExpired(currentTimestamp: number): void;

  /**
   * Check if a request exists
   */
  exists(id: number): boolean;
}

Test Cases

  • Adding a request and checking it exists returns true @test
  • Adding a request and querying pending for its topic returns the request @test
  • Updating a request with a response removes it from pending list @test
  • Querying by chain ID returns all requests for that chain @test
  • Removing expired requests deletes only requests past their expiry @test

Dependencies { .dependencies }

@walletconnect/types { .dependency }

Provides type definitions for WalletConnect Protocol v2, including JSON-RPC history interfaces.

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@walletconnect/types@2.21.x
tile.json