Umbrella Network Reference Application
Install packages.
git clone [email protected]:umbrella-network/babel.git
npm install
Setup a dotenv file (.env
) with local configuration values. Example:
# RPC provider eg. infura
BLOCKCHAIN_PROVIDER_URL=https://ropsten.infura.io/v3/***
# UMBrella Contract Registry contract address for ropsten:
REGISTRY_CONTRACT_ADDRESS=<get-it-from: https://umbrella-network.readme.io/docs/umb-token-contracts#contract-registry>
# UMBrella API Key:
API_KEY=0xXXXXXXX
For running FCD example, you need to have RPC provider URL
and you need to setup .env
, see example.env
.
Note: This example forking a blockchain using hardhat forking feature. If you provide RPC for BSC mainnet or ETH Ropsten (atm this are our two main environments) You will have access to all Umbrella feeds (Layer 2 and FCD).
Then open console and run
npm run test
You should get result like this:
Umbrella - Hello word examples for First Class Data - Layer 1
Deploying YourContract with Umbrella Registry: 0x4545e91d2e3647808670dd045ea5f4079b436ebc
umbChain:
0xfbe47aaddd6a0c795b01ab80648534a97f3b5d88
Fetching block from UMB Network for block height 40197
root:
0x4c11cc9dfb3d2dd21d2349042154aba98a9d86ca50608937af2fdf3fb5093275
timestamp: 1615420768
blockchain block number (anchor): 23858534
minter: 0xdc3ebc37da53a644d67e5e3b5ba4eef88d969d5c
✓ expect to present how to use Chain contract (5215ms)
55979780000000000000000
✓ expect to get latest price for BTC-USD (440ms)
2 passing (11s)
Run coders examples:
npx hardhat run scripts/coders.ts
Run API Client examples:
npx hardhat run scripts/api-client.ts
Run a proof verification example:
npx hardhat run scripts/proof-verification.ts
Run Passport examples:
npx hardhat run scripts/Passport/DatumRegistry.ts
In this repository there is a system composed by contracts/ExampleContract.sol
and contracts/L2Notifier
. The idea here is to have a contract that subscribes for a certain data at some future block. This data can be any Layer 2 Data like some cryptocurrency price or the Random Number (0x0000000000000000000000000000000000000000000046495845445f52414e44, decoded as FIXED_RAND
).
This contract is both where you register
your delivery request and expects to be notified
when your data is ready. An off-chain worker will be needed to fetch the data from Umbrella's API (block id, key, value and Merkle Proof). Reference on how to get L2D with Umbrella's Toolbox.
Example: listen to blocks minted by Umbrella's Chain Contract and when the desired block height is minted, fetch data and start a delivery from your worker towards L2Notifier. Notifier, at it's time, will call the ExampleContract
(here as the receiver) with the provided data and the proof checked, assuring the data is valid.
This contract holds the logic for the customer side. It implements an interface that verifies if the caller is the authorized contract and some other utilities, as the receiver's business logic requires.
We have provided an example Smart Contract (contracts/Passport/StandardDatumReceiver.sol
) that receives data from Passport. This Smart Contract is configured to have a variable that stores the minimum time between updates. That means that you can configure that value to approve
a Pallet every amount of seconds. Note that there is a modifier called onlyFromDatumRegistry
that is very important to prevent your contract having untrusted deliveries sent to it.
We also provided examples of interaction with the DatumRegistry
contract, which holds the information needed to have your Receiver
to receive data. Those examples can be found at scripts/Passport/DatumRegistry.ts
.