Return Zero

Harmony One DApp – The hard way – Part 1 – The CLI

Mr Silva

I am writing this as I found the documentation to be all over the place and I found it really hard to get started with any kind of development. I feel there is some kind of disconnect in the docs and there is a lot assumed knowledge which users or developers may not have. I will be writing this tutorial as I go about learning and building a simple DApp. I am making an assumption that you are new to Harmony and DApps as a whole but have some experience with programming. My hope here would be to get more devs on to Harmony and expand the ecosystem with more ideas and creativity and I expect you to do your bit and build some cool apps with Harmony😎

First things first, If you want to interact with any kind of crypto, you need to have a wallet, a wallet has a unique address which acts like your identity, this is similar to an email address but with added benefit of interacting with smart contracts, and smart contracts have functions which return things like your balance() and you could use a wallet to call functions like transfer(sender, receiver, amount) to be able to send tokens to other wallet addresses.

Now again, what is a wallet?

You may be familiar with Metamask, if not, do install it in chrome first, before you proceed, to get a feel for it. do setup a testNet account using these instructions and send your self some ONEs from this faucet.
The wallets mentioned above are software wallets, they hold your private keys as well as your wallet address, and you can use these wallets to interact with DApps like ViperSwap or LootSwap (Note: do not try to use a testNet wallet on live DApps, it will not work).

But we won’t be using these wallets for our tutorial, they are UI based and will cause you more pain and confusion down the line.
Also, we need to do this the hard way so that you learn the fundamentals. Hence, we will avoid as many UI tools as possible, this includes easy to use tools like the Remix IDE as you lose a lot of important details when you use them.
Once you learn to do it on the CLI, it will be a lot easier to do it using a UI and you will know exactly what you are doing. There is also the issue of separating your main accounts and test accounts along with their underlying private key and mnemonic which is annoying and could be a security risk if you end up committing any of these keys to your repo. We will also avoid using tools like Ganache and directly use the testNet as there are a few concepts that don’t carry over well from Ethereum to Harmony and the tutorials and documentation about Ganache out there on the web are meant for Ethereum and will only cause unnecessary confusion.

The first thing we do is setup the Harmony CLI, the command below is for Linux/Windows-WSL, if you use anything else, please refer the docs on how to set it up.

curl -LO https://harmony.one/hmycli && mv hmycli hmy && chmod +x hmy

let us begin with creating a new account, just follow the command below, enter a password and as you can see, you will get two things

user@My-Laptop:~$ ./hmy --node='https://api.s0.b.hmny.io' keys add account1 --passphrase
Enter passphrase: password456
Repeat the passphrase: password456

**Important** write this seed phrase in a safe place, it is the only way to recover your account if you ever forget your password

record shine spend borrow lamp congress result camp obtain cactus soldier film stamp scissors stool window damp adapt spare clap behind invest mouse mansion
ONE Address: one1lnxpzl0meyvrfflu2m9nw5p4j84nmmurcwv4pz

You might have noticed, we have specified a testNode URL else by default it will point to the mainNet which should not be used for development.

Now, what if you messed up something and want to start all over again, first find the where your keys are stored and delete the .hmy_cli directory.

user@My-Laptop:~$ ./hmy keys location
/home/user/.hmy_cli/account-keys

Now, we need to get a few ONEs to do some transactions, let us go over to the faucet that was mentioned before and enter our ONE address that we just generated and hit the send button. Make sure you use your own address 🀣 .

Once the transaction was successful, you should be able to view the new balance on your CLI as shown below,

user@My-Laptop:~$ ./hmy --node='https://api.s0.b.hmny.io' balances one1lnxpzl0meyvrfflu2m9nw5p4j84nmmurcwv4pz
 [
   {
     "shard": 0,
     "amount": 10101.000000000000000000
   }......

Now let us create another account,

user@My-Laptop:~$ ./hmy --node='https://api.s0.b.hmny.io' keys add account2 --passphrase
 Enter passphrase: password456
 Repeat the passphrase: password456
 Important write this seed phrase in a safe place, it is the only way to recover your account if you ever forget your password
 drama silent dinner sauce doll room cash abandon envelope funny august lawsuit reflect play develop taxi culture ridge sack vintage energy token swap virus
 ONE Address: one10xmrk67q2xpd2kzcmgnxevw8c7n47rpacdcxvc

Now let us try and send 100 ONEs from the first address to the second, make sure you use your own address,

user@My-Laptop:~$ ./hmy transfer --node='https://api.s0.b.hmny.io' \
   --from one1lnxpzl0meyvrfflu2m9nw5p4j84nmmurcwv4pz --to one10xmrk67q2xpd2kzcmgnxevw8c7n47rpacdcxvc \
    --from-shard 0 --to-shard 0 \
    --amount 100 --chain-id 1666700000 --passphrase

   Enter wallet keystore passphrase:
   {
     "transaction-hash": "0xd2b662b6d20fb5c682da228fb626ea2a1ab4054fd0119e43f51b60f98dc1a907",
     "blockchain-receipt": {
       "blockHash": "0xca82be50c1ff8ca622367eddb76dab86d6d119633a637c93a8af3835c2e3be35", 
....
....

Now if you are wondering what are shards and where did the chain-id come from, read this and this respectively, Now let us check the balance of the second address,

user@My-Laptop:~$ ./hmy --node='https://api.s0.b.hmny.io' balances one10xmrk67q2xpd2kzcmgnxevw8c7n47rpacdcxvc
 [
   {
     "shard": 0,
     "amount": 100.000000000000000000
   },
...
...

as you can see, the second address has received 100 ONEs. If you reached here, pat yourself on your back as it took me close to a day to get it working and put it all together πŸ˜….

In the next tutorial, I will try to focus on Truffle and a simple smart contract and how to get your own coin deployed on the testNet using the addresses that we generated and the testTokens that we received. If you have some feedback or feel like you are stuck anywhere, feel free to message me on reddit and I will try my best to help you out.

If you found this useful and feel like supporting me, here is my public ONE address πŸ™‚

Address: 0xeb5Ca70f9B2e852C1Fc74a9Fc12CA93679d3Bae4
ONE Style Address: one1adw2wrum96zjc878f20uzt9fxeua8whyacpf9t

do send me a message if you send ONEs, I’ll add your names to the list of contributors in the upcoming tutorial πŸ™‚

Tags:
Subscribe
Notify of
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Back to top