How to use Client Raindrop WITHOUT using the Hydrogen API
** I have published a video tutorial that follows this blog post step-by-step**
To understand this tutorial, it is important to first define some terms.
Hydrogen: a company that created a product — the Hydro API.
The Hydro API: an API that calls functions of Hydro smart contracts. Any other application, just like the Hydro API, can also call functions on Hydro smart contracts, either manually through sites like MyCrypto (as I will do in this tutorial), or programmatically through web3.
Hydro the Mobile App: This is a mobile app created by Hydrogen that connects end-users to the Hydrogen API. This creates HydroIDs for users which in turn allows them to manage their interactions with Hydro Smart Contracts. Thanks to the Hydro API, this doesn’t require any blockchain functionality native to the app itself.
HydroID: This is an ID generated through the Client-side Raindrop smart contract. Only one HydroID can be created for a given ethereum wallet. This ID is linked to Hydro smart contracts; for instance, when a user creates a Snowflake for personal data management, their unique, non-fungible Snowflake token is linked to their HydroID. The Hydrogen API only creates HydroIDs for wallets in the Hydro mobile app that are not currently meant to hold any funds; however, third-party applications could link HydroIDs to MetaMask wallets, native wallets, or other wallets based on the needs of their applications.
Hydro the decentralized project: the Hydro core team writes smart contracts that leverage the HYDRO token to add blockchain-enhanced financial services functionality to businesses. Blockchain developers around the world can freely recognize issues, make pull requests, or write their own contracts that also leverage HYDRO to bring blockchain functionality to businesses.
Hydro the ecosystem: This consists of developers writing and contributing to Hydro smart contracts, businesses using web3 to directly connect to Hydro smart contracts, and any and all clients these businesses serve.
Staking HYDRO: To ensure good actors in the HYDRO ecosystem, certain Hydro smart contracts require developers to maintain a certain balance of HYDRO. The Client Raindrop contract requires a balance of HYDRO for anyone who wants to register users. The owner of the HYDRO token contract (our team) can adjust the required amount of HYDRO staked (so we can reduce the requirement when needed based on scarcity of the token). However, this staking amount can never exceed 111,111,111 HYDRO for creating a HydroID on behalf of someone else, and 222,222 for creating a HydroID for yourself. We set this upper limit in order to maintain decentralization, so that if we control a large portion of the total supply, we can’t price out competitors. In the future, we intend to establish a decentralized ownership structure for the Owner contract, even despite its minimal power.
Scope of this tutorial
As part of Hydro the project, we have written a few smart contracts that leverage the HYDRO token: the server-side raindrop smart contract, the client-side raindrop smart contract, and the snowflake smart contract. We intend to write more contracts in accordance with our roadmap to make the Hydro token even more dynamic and useful. At the core of all the smart contracts we are creating is the HydroID. The HydroID is generated through our client-raindrop smart contract and creates a permanent, secure link to a user’s wallet that connects that user to the entire Hydro ecosystem.
In this tutorial, I will use the client raindrop smart contract to create a HydroID for a user that links to my personal Trust wallet. I will be doing this on the Rinkeby testnet using MyCrypto. A developer could use web3 to call the same functions I am calling and connect it to their own application. For instance, a bank who might want to make Raindrop native to their own mobile app for 2FA and use their own branding rather than making their users download a separate app, might use web3 to call these functions integrated into their own API. Alternatively, someone building a Linked-In style social media platform with native wallet functionality might want to call these functions to generate user HydroIDs that would link to those users’ snowflake non-fungible tokens. The full scope of programmatically interacting with Hydro Smart contracts is up to the imagination of the developer.
Acquiring Testnet Ether and Tokens
Before you can start, you will need to acquire ETH and HYDRO on the rinkeby testnet. To acquire ETH, follow the steps in this StackExchange answer:
RinkedBy official faucet uses 3rd party social network to prevent malicious actors. You only need to go to this page…ethereum.stackexchange.com
Next, you will need to acquire testnet HYDRO tokens. To do this, go to the contracts page of MyCrypto:
Connect with a wallet — I just used my MetaMask wallet for this. We will be using the Rinkeby Hydro token contract, which can be found here:
Source Code Copy Find Similiar Contracts pragma solidity ^0.4.18; /** * @title Ownable * @dev The Ownable contract has…rinkeby.etherscan.io
Leave “select existing contract” blank and instead paste the 0x4959c… address in the top left of the etherscan link into the “contract address” field. Paste the contract ABI from etherscan into the “ABI” field. Select the function getMoreTokens, set a gas limit and generate the transaction. Once complete, you should be able to view 10,000 HYDRO tokens from the 0x4959c address in your Rinkeby testnet wallet. If you are following these steps on the Ethereum Main Net, you would need to acquire the HYDRO from a third party.
While we’ve set the HYDRO main net staking requirement at 222,222 HYDRO, we are keeping the Rinkeby staking requirement at 10,000 HYDRO to make it easy for developers to follow these steps and test.
Note* throughout this tutorial, you will not actually use these 10,000 HYDRO. You will simply be unable to call these functions unless your wallet maintains a balance of 10,000 HYDRO. Thus, if you ever wanted to stop registering users, you could use your staked HYDRO for other HYDRO smart contracts or give it to other developers or a third party, or just leave them in your account.
Registering Users Through the Client-side Raindrop Smart Contract
Now that we’re set up, we can begin the actual process of interacting with the Client-side Raindrop Smart Contract. There are two ways to do this: you can either register your own HydroID or delegate someone else to do it on your behalf. Let’s start with the easier one — registering your own HydroID. Registering your own HydroID can be done by calling the signUpUser function of the Client-side Raindrop contract.
Return to the contracts page of MyCrypto, except this time paste the Client-side Raindrop contract address starting with 0xb29…. You can find this contract at the top left of the following etherscan page. Take the ABI from here as well:
Source Code Copy Find Similiar Contracts pragma solidity ^0.4.23; /** * @title Ownable * @dev The Ownable contract has…rinkeby.etherscan.io
Select the signUpDelegatedUser function, which takes the sole parameter casedUserName. Input whatever username you would like to register. Since these usernames are stored on the public blockchain, the HydrogenAPI generates random alphanumeric 7 character strings for this field; however, since I am doing this manually outside of the HydrogenAPI, I will just register a username called AnuragHydro.
Here, you can see the confirmed transaction:
Rinkeby (ETH) detailed transaction info for 0xae4c95811e3f5616ed3a12b5aea53082c26b5803885b5333fd7a3c0831b8cd49rinkeby.etherscan.io
Now, for the more interesting approach: registering a HydroID on behalf of another user. This will be useful for third-party applications who want to plug their users into the Hydro ecosystem. In order to register someone else as a user, you will need to collect two things from them:
- a signed message from them — this message must be a keccak 256 hash of “Create RaindropClient Hydro Account”
- their public address
In our implementation at Hydrogen, we store a keypair on the user’s mobile device through the Hydro app. This private key signs the message and sends the signed message along with their public address to our API which creates their HydroID.
For the purposes of this tutorial and going through the process manually, I will use MyCrypto’s signing functionality. Go to:
And make sure you’ve signed in with a new and separate ethereum address for which you will be conducting a delegated signup. The public address for mine is 0x3c5… You will need to paste the hash of the message “Create RaindropClient Hydro Account” — you can obtain the hash here:
and it should come out looking like this: 96c9259001bd030923ed09cd77ac733c1f82fe843ed92337c2b3953346d5a522. Add a 0x in the front and sign the message:
Once you’ve done this, the signature should appear below:
You will need to collect the “r” “s” and “v” from this signature. You can do this by pasting the signature into a fixed-width text editor (I use atom) and following these steps:
- remove the 0x from the start
- split the resulting string into three lines. Make sure the last line is 2 characters long, and the first and second lines are of equal length.
- Add 0x to the start of each of the first two lines.
At this point, the signature should look something like this
4. the “v” value is currently in hexadecimal format and needs to be converted to decimal format. You can make this conversion here:
Convert HEX to DECIMAL tables: find the decimal and binary representation of a hexadecimal number, calculate ...hextodecimal.com
1c in decimal is 28, so my v value is 28.
So now we’ve collected the following from the user we plan on registering:
public address = 0x3c5…
r = 0x02c9….
s = 0x7a5c….
v = 28
And we’ll name the HydroID for this user AnuragHydro3.0
So now we need to return to the Hydro Client-Raindrop smart contract on MyCrypto, except now we will be calling the signUpDelegatedUser function instead of signUpUser function. Enter the parameters you’ve collected above as follows:
And here’s the successful etherscan confirmation:
Rinkeby (ETH) detailed transaction info for 0x11664ee208cbc94219903fc960fbd27476b90abde6cb0c2cc4a160a86367df6crinkeby.etherscan.io
And voila! You’ve manually registered a separate user. Programmatically, you could call all these same functions the same way and register users en-masse.
Let me know if you’re able to replicate these steps successfully or integrate this process to be native to your own app! Alternatively, you are always able to have your users download the Hydro mobile app and sign up for the Hydro API via the Hydrogen website and simply connect your app to the Hydro API.