Scenario described here in the communication betwen Ink! Smart Contract on Astar Network and Ink! Phat Contract on Phala Network:
- A request to compute a random value between min and max values is stored in the Smart Contract
VrfConsumer
(on Astar Network) - The Phat Contract
VrfOracle
(on Phala Network) pulls the request from the Smart ContractVrfConsumer
(on Astar Network), generates the random value and sends the number to the Smart ContractVrfConsumer
(on Astar Network) - The Smart Contract
VrfConsumer
(on Astar Network) verifies the data used by the Phat ContractVrfOracle
and saves the number to be displayed in the UI
You can find a demo here: https://vrf-decentralized-oracle.substrate.fi/
The Phat Contract and Ink! Smart Contract have been built with the Phat Offchain Rollup. The full documentation of this SDK can be found here: https://github.com/Phala-Network/phat-offchain-rollup
To deploy this Phat Contract you can build the contract or use existing artifacts
More information here: phat/contracts/vrf_oracle/README.md
To build the contract:
cd phat/contracts/vrf_oracle
cargo contract build
All artifacts are here: phat/artifacts
To deploy this Ink! Smart Contract you can build the contract or use existing artifacts
More information here: ink/contracts/vrf_consumer/README.md
To build the contract:
cd ink/contracts/vrf_consumer
cargo contract build
All artifacts are here: ink/artifacts
You have to configure the rpc, the pallet id, the call id and the contract id to call the Smart Contract VrfConsumer
.
For example:
RPC=https://shibuya.public.blastapi.io
PALLET_ID=70
CALL_ID=6
#public key of the contract aesULxtrttD4VGe1oDWGnDihbknjQ44GYwN1L8RXMcWZxis
CONTRACT_ID=0xd0a5af9b2cd1fa7ca7b8c37cb1323b6596c7810b661085dbc32bdcd3a498219c
Meta transaction allows the Phat Contract to submit rollup tx with attest key signature while using arbitrary account to pay the gas fee. To enable meta tx in the unit test you have to set the private key
For example, the private key of account //bob: 0x398f0c28f98885e046333d4a41c19cee4c37368a9832c6502f6cfd182e2aef89
If you don't use Meta-Tx, you have to be sure that address of Phat Contract VrfOracle
will be able to pay transaction fees on Astar Network.
You have to grant the Phat Contract VrfOracle
as attestor in the Smart Contract VrfConsumer
.
If you use the Meta-Tx, you have to grant the ecdsa address.
If you don't use the Meta-Tx, you have to grant the sr25519 public key.
And grant the Phat Contract as attestor
You have to register the hash of the source code used to generate the random number by the Phat Contract VrfOracle
.