This package contains functions and classes useful for communicating with the blockchain.
You can install this package using npm
or
yarn
by running:
npm install --save @darkforest_eth/network
yarn add @darkforest_eth/network
When using this in a plugin, you might want to load it with skypack
import * as network from 'http://cdn.skypack.dev/@darkforest_eth/network';
- aggregateBulkGetter
- assertProperlySigned
- callWithRetry
- createContract
- createEthConnection
- ethToWei
- getAutoGasPrices
- getGasSettingGwei
- getResult
- gweiToWei
- isPurchase
- makeProvider
- neverResolves
- verifySignature
- waitForTransaction
- weiToEth
- weiToGwei
Ƭ AfterTransaction: (transactionRequest
: QueuedTransaction
, performanceMetrics
: unknown
) => Promise
<void
>
▸ (transactionRequest
, performanceMetrics
): Promise
<void
>
TxExecutor calls this after executing a transaction.
Name | Type |
---|---|
transactionRequest |
QueuedTransaction |
performanceMetrics |
unknown |
Promise
<void
>
Ƭ BeforeTransaction: (transactionRequest
: QueuedTransaction
) => Promise
<void
>
▸ (transactionRequest
): Promise
<void
>
TxExecutor calls this before executing a function to determine whether or not that function should execute. If this function throws, the transaction is cancelled.
Name | Type |
---|---|
transactionRequest |
QueuedTransaction |
Promise
<void
>
Ƭ ContractLoader<T
>: (address
: string
, provider
: providers.JsonRpcProvider
, signer?
: Wallet
) => Promise
<T
>
Name | Type |
---|---|
T |
extends Contract |
▸ (address
, provider
, signer?
): Promise
<T
>
Name | Type |
---|---|
address |
string |
provider |
providers.JsonRpcProvider |
signer? |
Wallet |
Promise
<T
>
Ƭ GasPriceSettingProvider: () => AutoGasSetting
| string
▸ (): 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.
AutoGasSetting
| string
Ƭ RetryErrorHandler: (i
: number
, e
: Error
) => void
▸ (i
, e
): void
Name | Type |
---|---|
i |
number |
e |
Error |
void
▸ Const
aggregateBulkGetter<T
>(total
, querySize
, getterFn
, onProgress?
): 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.
Name |
---|
T |
Name | Type | Description |
---|---|---|
total |
number |
the total amount of of items to get |
querySize |
number |
the chunk size |
getterFn |
(startIdx : number , endIdx : number ) => Promise <T []> |
a function that fetches something, given a start index and end index |
onProgress? |
(fractionCompleted : number ) => void |
whenever a chunk is loaded, this function is called with the fraction of individual items that have been loaded so far. |
Promise
<T
[]>
a list of each of the individual items that were loaded.
▸ assertProperlySigned(message
): void
Ensures that the given message was properly signed.
Name | Type |
---|---|
message |
SignedMessage <unknown > |
void
▸ Const
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.
Name |
---|
T |
Name | Type | Default value |
---|---|---|
fn |
(...args : any []) => Promise <T > |
undefined |
args |
any [] |
[] |
onError? |
RetryErrorHandler |
undefined |
maxRetries |
12 |
undefined |
retryInterval |
number |
1000 |
Promise
<T
>
▸ createContract<C
>(contractAddress
, contractABI
, provider
, signer?
): C
Name | Type |
---|---|
C |
extends Contract <C > |
Name | Type | Description |
---|---|---|
contractAddress |
string |
the address of the contract you want to connect to |
contractABI |
ContractInterface |
a javacript object representing the ABI |
provider |
JsonRpcProvider |
- |
signer? |
Wallet |
- |
C
▸ createEthConnection(rpcUrl
): Promise
<EthConnection
>
Name | Type |
---|---|
rpcUrl |
string |
Promise
<EthConnection
>
▸ ethToWei(eth
): BigNumber
Returns the given amount of eth in wei as a big integer.
Name | Type |
---|---|
eth |
number |
BigNumber
▸ getAutoGasPrices(): Promise
<GasPrices
>
Gets the current gas prices from xDai's price oracle. If the oracle is broken, return some sane defaults.
Promise
<GasPrices
>
▸ 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.
Name | Type |
---|---|
setting |
AutoGasSetting |
gasPrices |
GasPrices |
number
| undefined
▸ getResult(pendingTransaction
): Promise
<TransactionReceipt
>
When you submit a transaction via TxExecutor, you are given a PendingTransaction. This function either resolves when the transaction confirms, or rejects if there is any error.
Name | Type |
---|---|
pendingTransaction |
PendingTransaction |
Promise
<TransactionReceipt
>
▸ gweiToWei(gwei
): BigNumber
Returns the given amount of gwei in wei as a big integer.
Name | Type |
---|---|
gwei |
number |
BigNumber
▸ isPurchase(tx
): boolean
Whether or not some value is being transferred in this transaction.
Name | Type |
---|---|
tx |
providers.TransactionRequest |
boolean
▸ makeProvider(rpcUrl
): JsonRpcProvider
Creates a new {@link JsonRpcProvider}, and makes sure that it's connected to xDai if we're in production.
Name | Type |
---|---|
rpcUrl |
string |
JsonRpcProvider
▸ neverResolves(): Promise
<void
>
A function that just never resolves.s
Promise
<void
>
▸ verifySignature(message
, signature
, address
): boolean
Returns whether or not the given message was signed by the given address.
Name | Type |
---|---|
message |
string |
signature |
string |
address |
EthAddress |
boolean
▸ waitForTransaction(provider
, txHash
): Promise
<TransactionReceipt
>
Given a transaction hash and a JsonRpcProvider, waits for the given transaction to complete.
Name | Type |
---|---|
provider |
JsonRpcProvider |
txHash |
string |
Promise
<TransactionReceipt
>
▸ weiToEth(wei
): number
Returns the given amount of wei in gwei as a number.
Name | Type |
---|---|
wei |
BigNumber |
number
▸ weiToGwei(wei
): number
Returns the given amount of wei in gwei as a number.
Name | Type |
---|---|
wei |
BigNumber |
number