How to integrate with dApps
1. How to get the Hydrawallet
In order to get the Hydrawallet extension, please visit the following link: https://chrome.google.com/webstore/detail/hydrawallet/polcbnennmbhbdoafiicjgccofalcncl to add it to the browser and see more details/photos with information about the extension.
2. How to use Hydrawallet with DApps
Your DApp can use Hydrawallet to get information about a user’s account status (whether they are logged in the Hydrawallet, their account address and balance). Hydrawallet also enables your DApp to listen to a window event for any changes to the user’s account status. Your DApp can also use Hydrawallet to make callcontract and sendtocontract calls to the blockchain.
A) Connecting Hydrawallet
To use any of the above functionality, your DApp will first need to initiate a long-lived connection between Hydrawallet’s content script and background script. The code to do this is already in Hydrawallet, your DApp just needs to trigger the function by posting a window message.
This will populate the window.hydrawallet object in your webpage. The indow.hydrawallet.account values are automatically updated when a user logs in/out or the account balance changes.
B) Refreshing your page when Hydrawallet is installed or updated
You will probably want to refresh your DApp webpage when Hydrawallet is installed or updated. This allows your DApp to rerun window.postMessage({ message: { type: 'CONNECT_HYDRAWALLET' }}, '*') which would have previously failed to do anything while Hydrawallet was not yet installed. When Hydrawallet is installed or updated it will send all existing tabs an event message. To have that event message refresh your DApp and add the following event listener.
C) Hydrawallet user account status – login/logout
After connecting Hydrawallet to your DApp, you can use an event listener to get notified of any changes to the user’s account status (logging in/out, change in account balance).
Note that window.hydrawallet.account will still get updated even if you don’t set up this event listener. Your DApp just won’t be notified about the changes.
D) Using HydrawalletRPCProvider
RPC calls callcontract and sendtocontract can be directly made via HydrawalletRPCProvider which is available to any webpage that connects to Hydrawallet.
Make sure that window.hydrawallet.rpcProvider is defined before using it.
E) Using Hydraweb3
You may also use our Hydraweb3 convenience library to make sendtocontract or callcontract calls. See the instructions in the Github repo here: https://github.com/Hydra-Chain/hydraweb3-js
Last updated