Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Web3Public

Class containing methods for calling contracts in order to obtain information from the blockchain. To send transaction or execute contract method use Web3Private.

Hierarchy

  • Web3Public

Index

Constructors

Methods

  • batchEstimatedGas(abi: AbiItem[], contractAddress: string, fromAddress: string, callsData: BatchCall[]): Promise<(null | BigNumber)[]>
  • Get estimated gas of several contract method executions via rpc batch request.

    Parameters

    • abi: AbiItem[]

      Contract ABI.

    • contractAddress: string

      Contract address.

    • fromAddress: string

      Sender address.

    • callsData: BatchCall[]

      Transactions parameters.

    Returns Promise<(null | BigNumber)[]>

    List of contract execution estimated gases. If the execution of the method in the real blockchain would not be reverted, then the list item would be equal to the predicted gas limit. Else (if you have not enough balance, allowance ...) then the list item would be equal to null.

  • callContractMethod<T>(contractAddress: string, contractAbi: AbiItem[], methodName: string, options?: { from?: string; methodArguments?: unknown[]; value?: string }): Promise<T>
  • Calls pure method of smart-contract and returns its output value.

    Type Parameters

    • T = string

    Parameters

    • contractAddress: string

      Address of smart-contract which method is to be executed.

    • contractAbi: AbiItem[]

      Abi of smart-contract which method is to be executed.

    • methodName: string

      Called method name.

    • options: { from?: string; methodArguments?: unknown[]; value?: string } = ...
      • Optional from?: string
      • Optional methodArguments?: unknown[]
      • Optional value?: string

    Returns Promise<T>

  • callForTokenInfo(tokenAddress: string, tokenFields?: SupportedTokenField[]): Promise<Partial<Record<SupportedTokenField, string>>>
  • Gets ERC-20 token info by address.

    Parameters

    • tokenAddress: string

      Address of token.

    • tokenFields: SupportedTokenField[] = ...

      Token's fields to get.

    Returns Promise<Partial<Record<SupportedTokenField, string>>>

  • callForTokensInfo(tokenAddresses: string[] | readonly string[]): Promise<Record<SupportedTokenField, undefined | string>[]>
  • checkBalance(token: { address: string; decimals: number; symbol: string }, amount: BigNumber, userAddress: string): Promise<void>
  • Checks if the specified address contains the required amount of these tokens. Throws an InsufficientFundsError if balance is insufficient.

    Parameters

    • token: { address: string; decimals: number; symbol: string }

      Token, which balance you need to check.

      • address: string
      • decimals: number
      • symbol: string
    • amount: BigNumber

      Required balance.

    • userAddress: string

      The address, where the required balance should be.

    Returns Promise<void>

  • getAllowance(tokenAddress: string, ownerAddress: string, spenderAddress: string): Promise<BigNumber>
  • Calls allowance method in ERC-20 token contract.

    Parameters

    • tokenAddress: string

      Address of the smart-contract corresponding to the token.

    • ownerAddress: string

      Wallet address to spend from.

    • spenderAddress: string

      Wallet or contract address, allowed to spend.

    Returns Promise<BigNumber>

    Token's amount, allowed to be spent.

  • getBalance(address: string, tokenAddress?: string): Promise<BigNumber>
  • Gets account native or ERC-20 token balance in wei.

    Parameters

    • address: string

      Wallet address, whose balance you want to find out.

    • Optional tokenAddress: string

      Address of the smart-contract corresponding to the token, {@link NATIVE_TOKEN_ADDRESS} is used as default.

    Returns Promise<BigNumber>

  • getBlock(blockId?: BlockNumber): Promise<BlockTransactionString>
  • getBlockNumber(): Promise<number>
  • getEstimatedGas(contractAbi: AbiItem[], contractAddress: string, methodName: string, methodArguments: unknown[], fromAddress: string, value?: string | BigNumber): Promise<null | BigNumber>
  • Predicts the volume of gas required to execute the contract method.

    Parameters

    • contractAbi: AbiItem[]

      Abi of smart-contract.

    • contractAddress: string

      Address of smart-contract.

    • methodName: string

      Method which execution gas limit is to be calculated.

    • methodArguments: unknown[]

      Arguments of the contract method.

    • fromAddress: string

      The address for which the gas calculation will be called.

    • Optional value: string | BigNumber

      The value transferred for the call “transaction” in wei.

    Returns Promise<null | BigNumber>

    Estimated gas limit.

  • getGasPrice(): Promise<string>
  • getGasPriceInETH(): Promise<BigNumber>
  • getPastEvents(contractAddress: string, contractAbi: AbiItem[], eventName: string, options: { blocksAmount: number; toBlock: number | "latest" }): Promise<EventData[]>
  • Parameters

    • contractAddress: string
    • contractAbi: AbiItem[]
    • eventName: string
    • options: { blocksAmount: number; toBlock: number | "latest" }
      • blocksAmount: number
      • toBlock: number | "latest"

    Returns Promise<EventData[]>

  • getTokenBalance(address: string, tokenAddress: string): Promise<BigNumber>
  • Gets ERC-20 tokens balance in wei.

    Parameters

    • address: string

      Wallet address, whose balance you want to find out.

    • tokenAddress: string

      Address of the smart-contract corresponding to the token.

    Returns Promise<BigNumber>

  • getTokensBalances(address: string, tokensAddresses: string[]): Promise<BigNumber[]>
  • getTransactionByHash(hash: string, attempt?: number, attemptsLimit?: number, delay?: number): Promise<null | Transaction>
  • Gets a transaction by hash in several attempts.

    Parameters

    • hash: string

      Hash of the target transaction.

    • Optional attempt: number

      Current attempt number.

    • Optional attemptsLimit: number

      Maximum allowed number of attempts.

    • Optional delay: number

      Delay before next attempt in ms.

    Returns Promise<null | Transaction>

  • getTransactionReceipt(hash: string): Promise<TransactionReceipt>
  • healthCheck(timeoutMs?: number): Promise<boolean>
  • Health-check current rpc node.

    Parameters

    • timeoutMs: number = 4000

      Acceptable node response timeout.

    Returns Promise<boolean>

    Null if healthcheck is not defined for current blockchain, else node health status.

  • multicallContractMethod<Output>(contractAddress: string, contractAbi: AbiItem[], methodName: string, methodCallsArguments: unknown[][]): Promise<ContractMulticallResponse<Output>[]>
  • Uses multicall to make several calls of one method in one contract.

    Type Parameters

    • Output

    Parameters

    • contractAddress: string

      Target contract address.

    • contractAbi: AbiItem[]

      Target contract abi.

    • methodName: string

      Method name.

    • methodCallsArguments: unknown[][]

      Method parameters array, for each method call.

    Returns Promise<ContractMulticallResponse<Output>[]>

  • multicallContractMethods<Output>(contractAddress: string, contractAbi: AbiItem[], methodsData: MethodData[]): Promise<ContractMulticallResponse<Output>[]>
  • Uses multicall to make several methods calls in one contract.

    Type Parameters

    • Output

    Parameters

    • contractAddress: string

      Target contract address.

    • contractAbi: AbiItem[]

      Target contract abi.

    • methodsData: MethodData[]

      Methods data, containing methods' names and arguments.

    Returns Promise<ContractMulticallResponse<Output>[]>

  • multicallContractsMethods<Output>(contractAbi: AbiItem[], contractsData: { contractAddress: string; methodsData: MethodData[] }[]): Promise<ContractMulticallResponse<Output>[][]>
  • Uses multicall to make many methods calls in several contracts.

    Type Parameters

    • Output

    Parameters

    • contractAbi: AbiItem[]

      Target contract abi.

    • contractsData: { contractAddress: string; methodsData: MethodData[] }[]

      Contract addresses and methods data, containing methods' names and arguments.

    Returns Promise<ContractMulticallResponse<Output>[][]>

  • setProvider(provider: provider): void

Generated using TypeDoc