This guide presents an example of how to use the on-chain issuer. We created a small application, where we communicate with Metamask to retrieve the user's balance and a claim about this balance is generated via the on-chain issuer.
There are three main components in this application:
- On-chain issuer (demo|contract)
- Server for user authorization
- Front-end component for communication with Metamask
Currently, the state contract on the mainnet does not support onchain issuers. Please, use the Mumbai network instead.
- Node js => 18.x
- Go => 1.20.x
- npm => 9.x.x
- docker => 20.x
- Polygon ID wallet app
How to run the On-chain Issuer
Clone this repository:
git clone https://github.com/0xPolygonID/onchain-issuer-integration-demo
All the variables which need to be altered are in the
ONCHAIN_ISSUER_CONTRACT_ADDRESS=<ONCHAIN_ISSUER_CONTRACT_ADDRESS> URL_MUMBAI_NODE=<URL_TO_POLYGON_MUMBAI_NODE> URL_POLYGON_NODE=<URL_TO_POLYGON_MAINNET_NODE> ONCHAIN_CONTRACT_OWNER=<PRIVATE_KEY_IS_USED_FOR_DEPLOY_ONCHAIN_ISSUER_CONTRACT> MUMBAI_CONTRACT_STATE_ADDRESS=0x134B1BE34911E39A8397ec6289782989729807a4 MAIN_CONTRACT_STATE_ADDRESS=0x624ce98D2d27b20b8f8d521723Df8fC4db71D79D ONCHAIN_ISSUER_CONTRACT_BLOCKCHAIN=<BLOCKCHAIN_OF_ISSUER_CONTRACT> ONCHAIN_ISSUER_CONTRACT_NETWORK=<BLOCKCHAIN_OF_WITH_ISSUER_CONTRACT>
Deploy an on-chain issuer contract. You can use this sample here or create your own smart contract with custom logic.
Use the following State Contract addresses:
- For mumbai network:
- For mainnet network:
You can find more information on how to deploy a smart contract using Hardhat in this readme.
- For mumbai network:
Fill in the configuration files with the actual values.
ONCHAIN_ISSUER_CONTRACT_ADDRESSshould be retrieved from the smart contract deployment.
URL_MUMBAI_NODEis easily acquired with any Infrastructure provider, such as Alchemy, Infura etc.
URL_POLYGON_NODEis easily acquired with any Infrastructure provider, such as Alchemy, Infura etc.
ONCHAIN_CONTRACT_OWNERis where a private key should be set to deploy the contract.
MUMBAI_CONTRACT_STATE_ADDRESSrepresents the already deployed Mumbai State Contract and shouldn't be changed.
MAIN_CONTRACT_STATE_ADDRESSrepresents the already deployed Mainnet State Contract and shouldn't be changed.
ONCHAIN_ISSUER_CONTRACT_BLOCKCHAINsets the blockchain where the on-chain issuer contract was deployed as
ONCHAIN_ISSUER_CONTRACT_NETWORKsets the blockchain network where the on-chain issuer contract was deployed, as
Run the run.sh script:
Don't forget to download and install the Polygon ID wallet app before you go the next steps. - For Android: <a href="https://play.google.com/store/apps/details?id=com.polygonid.wallet" target="_blank">Polygon ID on Google Play</a> - For iOS: <a href="https://apps.apple.com/us/app/polygon-id/id1629870183" target="_blank">Polygon ID on the App Store</a>
Issue and fetch credential
http://localhost:3000in your web browser and click on Sign Up.
Scan the QR code with your Polygon ID wallet app and follow the instructions on the application.
You will see your DID and now you can connect to MetaMask. Follow the flow on the MetaMask app.
The On-chain issuer application will now display your account. Now share your account balance with the application.
The account balance will be shown in gwei together with some other information about the claim.
Clicking on Get Claim will finally lead to the QR Code used to fetch the credential with MTP proof. Here we are making a request to the on-chain issuer node. This node then saves this claim in a contract address. Scan it with the Polygon ID wallet and the credential should be added to the mobile app.
Here is the credential on the mobile app:
How to verify the balance claim
- Go to the Verifier website.
customfrom the dropdown menu.
Fill up the form.
- Circuit Id: Credential Atomic Query MTP;
- URL: https://gist.githubusercontent.com/ilya-korotya/b06baa37453ed9aedfcb79100b84d51f/raw/balance-v1.jsonld
- Type: BalanceCredential
- Field: balance
- Operator: all the operators work for the claim. More information here
- Value: set the value that you want to verify.
Here is an example:
Use the mobile application to scan the QR code and complete the verification process. The verifier will check revocation status and additional information and the proof will be sent to the verifier. The Verifier website will present then the proof information.
New Polygon ID Documentation Website Available!
We've released a new version of our documention. Head to devs.polygonid.com to check it out.