gas-price-oracle/README.md

56 lines
1.4 KiB
Markdown
Raw Normal View History

2020-05-27 18:52:57 +03:00
# Gas Price Oracle library for Ethereum dApps
2020-06-04 02:08:09 +03:00
A library that has a collection of onchain and offchain gas price oracle URLs
2020-05-27 18:52:57 +03:00
2020-06-04 02:08:09 +03:00
Current offchain list:
- https://ethgasstation.info/json/ethgasAPI.json
- https://gas-oracle.zoltu.io/
- https://www.etherchain.org/api/gasPriceOracle
- https://gasprice.poa.network/
Current onchain list:
- [chainlink](https://etherscan.io/address/0xA417221ef64b1549575C977764E651c9FAB50141)
## Installation
2020-05-27 18:52:57 +03:00
`npm i gas-price-oracle`
2020-06-02 16:29:12 +03:00
## Import
2020-05-27 18:52:57 +03:00
```js
const { GasPriceOracle } = require('gas-price-oracle');
2020-06-02 16:29:12 +03:00
```
## Usage
### Basic
2020-06-04 02:08:09 +03:00
2020-06-02 16:29:12 +03:00
```js
2020-05-27 18:52:57 +03:00
2020-06-04 02:08:09 +03:00
const options = {
defaultRpc: 'https://api.mycryptoapi.com/eth'
}
const oracle = new GasPriceOracle(options);
// optional fallbackGasPrices
const fallbackGasPrices = {
instant: 70, fast: 31, standard: 20, low: 7
}
oracle.gasPrices(fallbackGasPrices).then((gasPrices) => {
console.log(gasPrices) // { instant: 50, fast: 21, standard: 10, low: 3 }
2020-06-02 16:29:12 +03:00
});
```
### Offchain oracles only
```js
const oracle = new GasPriceOracle();
2020-06-04 02:08:09 +03:00
oracle.fetchGasPricesOffChain().then((gasPrices) => {
console.log(gasPrices) // { instant: 50, fast: 21, standard: 10, low: 3 }
2020-06-02 16:29:12 +03:00
});
```
### Custom RPC URL for onchain oracles
```js
2020-06-04 02:08:09 +03:00
const defaultRpc = 'https://mainnet.infura.io/v3/<API_KEY>'
const oracle = new GasPriceOracle({ defaultRpc });
2020-06-02 16:29:12 +03:00
2020-06-04 02:08:09 +03:00
oracle.fetchGasPricesOnChain().then((gasPrices) => {
console.log(gasPrices) // 21
2020-05-27 18:52:57 +03:00
});
```