https://github.com/api3dao/beacon-reader-example
https://github.com/api3dao/beacon-reader-example
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/api3dao/beacon-reader-example
- Owner: api3dao
- Archived: true
- Created: 2021-12-14T14:45:48.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-03-07T07:37:45.000Z (over 3 years ago)
- Last Synced: 2025-03-02T16:16:07.475Z (over 1 year ago)
- Language: JavaScript
- Size: 1.32 MB
- Stars: 0
- Watchers: 7
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Beacon Reader Example
> An example project for reading beacon values from a smart contract
1. Tests that use a `MockRrpBeaconServer` contract to simulate reading a
beacon.
2. A script to deploy the `BeaconReaderExample` contract to one of the supported
networks. This script will use the address of the `RrpBeaconServer` contract
deployed on the selected network. You can see the `deployments/` directory for
the address of the deployed contract.
3. A script to whitelist `BeaconReaderExample` for it to be able to read a specific beacon.
4. A script to have `BeaconReaderExample` read the beacon.
## Instructions
_You are recommended to follow our [docs](https://docs.api3.org/beacon/v0.1/introduction/hackathon.html) instead._
Install the dependencies:
```sh
npm install
```
### Tests
Run the unit tests defined in the `test/` directory:
```sh
npm run test
```
### Network: `localhost`
Start a local Ethereum node on a separate terminal:
```sh
npm run eth-node
```
Deploy `MockRrpBeaconServer`, `BeaconReaderExample`, and mock-set a beacon value:
```sh
npm run deploy:localhost
```
You can skip the whitelisting step on `localhost`.
Have `BeaconReaderExample` read the mocked beacon value and print it on the terminal:
```sh
npm run read-beacon:localhost
```
### Networks: `ropsten`, `rinkeby`, `goerli`, `polygon-mumbai`
Create a `credentials.json` file at the root of the repo, similar to `credentials.example.json`.
Fill in the blockchain provider URL (e.g., `https://rpc-mumbai.matic.today` for `polygon-mumbai`).
Fill in the mnemonic with one that belongs to a wallet that you have funded using a faucet.
Deploy `BeaconReaderExample` that is pointed to the pre-deployed `RrpBeaconServer`:
```sh
npm run deploy:polygon-mumbai
```
Whitelist the `BeaconReaderExample` you have deployed for the `ETH/USD` beacon powered by Amberdata:
```sh
npm run whitelist-reader:polygon-mumbai
```
Have `BeaconReaderExample` read the beacon value and print it on the terminal:
```sh
npm run read-beacon:polygon-mumbai
```
You can replace `polygon-mumbai` with `ropsten`, `rinkeby` or `goerli` to work on one of these networks.
You can read beacons other than `ETH/USD` by modifying `scripts/whitelist-reader.js` and `scripts/read-beacon.js`.
Refer to the [docs](https://docs.api3.org/beacon/v0.1/reference/beacon-ids.html) for a complete list.