An example project for reading beacon values from a smart contract
- Tests that use a
MockRrpBeaconServercontract to simulate reading a beacon. - A script to deploy the
BeaconReaderExamplecontract to one of the supported networks. This script will use the address of theRrpBeaconServercontract deployed on the selected network. You can see thedeployments/directory for the address of the deployed contract. - A script to whitelist
BeaconReaderExamplefor it to be able to read a specific beacon. - A script to have
BeaconReaderExampleread the beacon.
You are recommended to follow our docs instead.
Install the dependencies:
npm installRun the unit tests defined in the test/ directory:
npm run testStart a local Ethereum node on a separate terminal:
npm run eth-nodeDeploy MockRrpBeaconServer, BeaconReaderExample, and mock-set a beacon value:
npm run deploy:localhostYou can skip the whitelisting step on localhost.
Have BeaconReaderExample read the mocked beacon value and print it on the terminal:
npm run read-beacon:localhostCreate 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:
npm run deploy:polygon-mumbaiWhitelist the BeaconReaderExample you have deployed for the ETH/USD beacon powered by Amberdata:
npm run whitelist-reader:polygon-mumbaiHave BeaconReaderExample read the beacon value and print it on the terminal:
npm run read-beacon:polygon-mumbaiYou 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 for a complete list.