eth-provider-types
This package provides types for Ethereum JSON RPC APIs. This includes:
import {
EthProvider,
EthMethod,
EthEvent,
EthProviderMessageType,
EthProviderRpcErrorCode,
EthBlockNumberTag,
EthMethodParams,
EthMethodResults,
EthEventParams,
EthProviderMessageData,
EthTransaction,
EthTransactionComplete,
EthTransactionPending,
EthTransactionSend,
EthTransactionCall,
EthTransactionReceipt,
EthBlock,
EthBlockComplete,
EthBlockPending,
EthLog,
EthLogComplete,
EthLogPending,
EthProviderMessage,
EthProviderRpcError,
EthProviderConnectInfo,
} from 'eth-provider-types';
You can use these types to create an Ethereum provider that is strongly typed:
import { EthProvider, EthMethod, EthTransactionReceipt } from 'eth-json-rpc-types';
class MyProvider implements EthProvider {
request({ method, params }) {
}
}
const provider = new MyProvider();
const eth_accounts: string[] = provider.request({ method: EthMethod.eth_accounts });
const eth_getTransactionReceipt: EthTransactionReceipt = provider.request({
method: EthMethod.eth_accounts,
params: ['0x0...'],
});
const eth_getBlockByHash = provider.request({
method: EthMethod.eth_getBlockByHash,
params: [123],
});