6.8.13 • Published 5 days ago

@dfares/network v6.8.13

Weekly downloads
-
License
MIT
Repository
-
Last release
5 days ago

@dfares/network

This package contains functions and classes useful for communicating with the blockchain.

Installation

You can install this package using npm or yarn by running:

npm install --save @dfares/network
yarn add @dfares/network

When using this in a plugin, you might want to load it with skypack

import * as network from 'http://cdn.skypack.dev/@dfares/network';

Table of contents

Classes

Interfaces

Type aliases

Functions

Type aliases

AfterTransaction

Ƭ AfterTransaction: (transactionRequest: Transaction, performanceMetrics: unknown) => Promise<void>

Type declaration

▸ (transactionRequest, performanceMetrics): Promise<void>

TxExecutor calls this after executing a transaction.

Parameters
NameType
transactionRequestTransaction
performanceMetricsunknown
Returns

Promise<void>


BeforeQueued

Ƭ BeforeQueued: (id: TransactionId, intent: TxIntent, overrides?: providers.TransactionRequest) => Promise<void>

Type declaration

▸ (id, intent, overrides?): Promise<void>

TxExecutor calls this before queueing a function to determine whether or not that function should be queued. If this function rejects, a transaction is not queued.

Parameters
NameType
idTransactionId
intentTxIntent
overrides?providers.TransactionRequest
Returns

Promise<void>


BeforeTransaction

Ƭ BeforeTransaction: (transactionRequest: Transaction) => Promise<void>

Type declaration

▸ (transactionRequest): Promise<void>

TxExecutor calls this before executing a function to determine whether or not that function should execute. If this function rejects, the transaction is cancelled.

Parameters
NameType
transactionRequestTransaction
Returns

Promise<void>


ContractLoader

Ƭ ContractLoader<T>: (address: string, provider: providers.JsonRpcProvider, signer?: Wallet) => Promise<T>

Type parameters

NameType
Textends Contract

Type declaration

▸ (address, provider, signer?): Promise<T>

Parameters
NameType
addressstring
providerproviders.JsonRpcProvider
signer?Wallet
Returns

Promise<T>


GasPriceSettingProvider

Ƭ GasPriceSettingProvider: (transactionRequest: Transaction) => AutoGasSetting | string

Type declaration

▸ (transactionRequest): AutoGasSetting | string

Returns either a string that represents the gas price we should use by default for transactions, or a string that represents the fact that we should be using one of the automatic gas prices.

Parameters
NameType
transactionRequestTransaction
Returns

AutoGasSetting | string


RetryErrorHandler

Ƭ RetryErrorHandler: (i: number, e: Error) => void

Type declaration

▸ (i, e): void

Parameters
NameType
inumber
eError
Returns

void

Functions

aggregateBulkGetter

aggregateBulkGetter<T>(total, querySize, getterFn, onProgress?, offset?): Promise<T[]>

A useful utility function that breaks up the proverbial number line (defined by {@code total} and {@code querySize}), and calls {@code getterFn} for each of the sections on the number line.

Type parameters

Name
T

Parameters

NameTypeDefault valueDescription
totalnumberundefinedthe total amount of of items to get
querySizenumberundefinedthe chunk size
getterFn(startIdx: number, endIdx: number) => Promise<T[]>undefineda function that fetches something, given a start index and end index
onProgress?(fractionCompleted: number) => voidundefinedwhenever a chunk is loaded, this function is called with the fraction of individual items that have been loaded so far.
offsetnumber0the index to start fetching, can be used to skip previously fetched elements.

Returns

Promise<T[]>

a list of each of the individual items that were loaded.


assertProperlySigned

assertProperlySigned(message): void

Ensures that the given message was properly signed.

Parameters

NameType
messageSignedMessage<unknown>

Returns

void


callWithRetry

callWithRetry<T>(fn, args?, onError?, maxRetries?, retryInterval?): Promise<T>

Calls the given function, retrying it if there is an error.

todo Get rid of this, and make use of ContractCaller.

Type parameters

Name
T

Parameters

NameTypeDefault value
fn(...args: any[]) => Promise<T>undefined
argsany[][]
onError?RetryErrorHandlerundefined
maxRetries12DEFAULT_MAX_CALL_RETRIES
retryIntervalnumber1000

Returns

Promise<T>


createContract

createContract<C>(contractAddress, contractABI, provider, signer?): C

Type parameters

NameType
Cextends Contract<C>

Parameters

NameTypeDescription
contractAddressstringthe address of the contract you want to connect to
contractABIContractInterfacea javacript object representing the ABI
providerJsonRpcProvider-
signer?Wallet-

Returns

C


createEthConnection

createEthConnection(rpcUrl): Promise<EthConnection>

Parameters

NameType
rpcUrlstring

Returns

Promise<EthConnection>


ethToWei

ethToWei(eth): BigNumber

Returns the given amount of eth in wei as a big integer.

Parameters

NameType
ethnumber

Returns

BigNumber


getAutoGasPrices

getAutoGasPrices(): Promise<GasPrices>

Gets the current gas prices from blockchain's price oracle. If the oracle is broken, return some sane defaults.

Returns

Promise<GasPrices>


getGasSettingGwei

getGasSettingGwei(setting, gasPrices): number | undefined

Given the user's auto gas setting, and the current set of gas prices on the network, returns the preferred gas price. If an invalid {@link AutoGasSetting} is provided, then returns undefined.

Parameters

NameType
settingAutoGasSetting
gasPricesGasPrices

Returns

number | undefined


gweiToWei

gweiToWei(gwei): BigNumber

Returns the given amount of gwei in wei as a big integer.

Parameters

NameType
gweinumber

Returns

BigNumber


isPurchase

isPurchase(tx?): boolean

Whether or not some value is being transferred in this transaction.

Parameters

NameType
tx?TransactionRequest

Returns

boolean


makeProvider

makeProvider(rpcUrl): providers.JsonRpcProvider

Creates a new {@link JsonRpcProvider}, and makes sure that it's connected to blockchain if we're in production.

Parameters

NameType
rpcUrlstring

Returns

providers.JsonRpcProvider


neverResolves

neverResolves(): Promise<void>

A function that just never resolves.s

Returns

Promise<void>


verifySignature

verifySignature(message, signature, addr): boolean

Returns whether or not the given message was signed by the given address.

Parameters

NameType
messagestring
signaturestring
addrundefined | EthAddress

Returns

boolean


waitForTransaction

waitForTransaction(provider, txHash): Promise<providers.TransactionReceipt>

Given a transaction hash and a JsonRpcProvider, waits for the given transaction to complete.

Parameters

NameType
providerJsonRpcProvider
txHashstring

Returns

Promise<providers.TransactionReceipt>


weiToEth

weiToEth(wei): number

Returns the given amount of wei in gwei as a number.

Parameters

NameType
weiBigNumber

Returns

number


weiToGwei

weiToGwei(wei): number

Returns the given amount of wei in gwei as a number.

Parameters

NameType
weiBigNumber

Returns

number

6.8.13

5 days ago

6.8.12

20 days ago

6.8.11

20 days ago

6.8.10

1 month ago

6.8.9

1 month ago

6.8.8

1 month ago

6.8.7

1 month ago

6.8.6

3 months ago

6.8.5

6 months ago

6.8.4

10 months ago

6.8.3

10 months ago

6.8.2

10 months ago

6.8.1

10 months ago

6.8.0

10 months ago

6.8.0-dev.0

10 months ago