Harmony
Support ForumGithubTelegramDiscord
  • Welcome
  • 🎶General
    • Introduction
      • What is Harmony?‌
      • Roadmap
      • Strategy & Architecture
      • Study Materials
      • FAQ
    • Technology
      • Key Features
      • Randomness
      • Sharding
      • Consensus
      • Effective Proof-of-Stake
      • Tokenomics
      • Transactions
    • LayerZero Bridge
      • Important Notice
      • Bridge tutorial
      • FAQ
        • What token will I get after the bridge
        • How to find a bridged token address
    • Ecosystem
      • Wallets
        • 1Wallet
        • Gnosis Safe
        • Hardware Wallets
          • Trezor
          • Ledger Nano
            • Ledger with Metamask
            • Download & Setup
            • Ledger with HMY CLI
            • Ledger with Staking Dashboard
              • Sign In With Ledger
              • Sending transactions via Ledger
              • Staking Transactions via Ledger
          • Safepal
            • Download & setup
            • Create/import account
            • Send transaction
        • Browser Extension Wallets
          • Metamask
            • Installing MetaMask
            • Adding Harmony
            • Create a New Account
            • Sending & Receiving
            • Adding Custom Harmony Tokens
            • Import an Account
          • Math Wallet
            • Download & Setup
            • Create/Import/Export Wallet
            • Sending Transactions
            • Staking
            • Collecting Rewards
            • Undelegating
          • Harmony Chrome Extension Wallet
        • Desktop Wallets
          • Guarda Wallet
          • Staking4All Wallet
        • Mobile Wallets
          • Metamask Wallet
          • Blits Wallet
          • Cobo Wallet
          • Frontier Wallet
          • Guarda Wallet
          • Infinity Wallet
          • ONTO Wallet
          • Sef Wallet
          • Trust Wallet
          • Trustee Wallet
        • Web Wallets
          • Guarda Wallet
        • HMY CLI (Harmony Command Line Interface)
          • Download & Setup
          • Create or Import Wallet
          • Sending Transactions
          • Staking Transactions
          • Querying Balances
          • Querying the Blockchain
          • List of Transaction Error Messages
          • Cookbook
          • Other CLI References
      • DApps
        • User Guide
        • DeFi
          • Sushi
          • Onsen
        • CLI 1Wallet User Guide
        • Media
          • Timeless
        • FAQ
        • NFTs
      • Partners
        • Exchanges
        • Fiat Gateways
        • DeFi Protocols
      • Integrations
      • Cross-Border Finance
      • DAOs
        • Components & Tools
          • Snapshot
        • Community DAO
        • Validator DAO
        • Developer DAO
    • Community
  • 🏗️Developers
    • Getting Started
      • Network & Faucets
      • List of RPC Providers
      • Remix IDE
      • Dev Environment Setup
      • Ethereum Compatibility
    • Deploying on Harmony
      • Using Remix
        • Ethereum Remix
        • Harmony Remix
      • Using Truffle
      • Using Hardhat
      • Using Web3
      • Using Harmony-JS
        • Setup
        • Compile & Deploy
        • Demo: Deploying an Ethereum Smart Contract on Harmony
      • Deploy HRC20
      • Smart Contract Verification
    • SDK
      • Web3.js
        • Using Web3.js to Send Transactions on Harmony
        • Find the last transaction
      • JavaScript SDK
      • Go CLI
      • Java SDK
      • Python SDK
      • Harmony Ethers.js Wrapper
    • API
      • Methods
        • Account Methods
          • hmy_getBalanceByBlockNumber
          • hmy_getTransactionCount
          • hmy_getBalance
        • Filter Methods
          • hmy_getFilterLogs
          • hmy_newFilter
          • hmy_newPendingTransactionFilter
          • hmy_newBlockFilter
          • hmy_getFilterChanges
          • hmy_getLogs
        • Transaction Related Methods
          • hmy_getStakingTransactionByBlockHashAndIndex
          • hmy_getStakingTransactionByBlockNumberAndIndex
          • hmy_getStakingTransactionByHash
          • hmy_getCurrentTransactionErrorSink
          • hmy_getPendingCrossLinks
          • hmy_getPendingCXReceipts
          • hmy_getCXReceiptByHash
          • hmy_pendingTransactions
          • hmy_sendRawStakingTransaction
          • hmy_getTransactionsHistory
          • hmy_sendRawTransaction
          • hmy_getTransactionReceipt
          • hmy_getBlockTransactionCountByHash
          • hmy_getBlockTransactionCountByNumber
          • hmy_getTransactionByHash
          • hmy_getTransactionByBlockNumberAndIndex
          • hmy_getTransactionByBlockHashAndIndex
          • hmy_getBlockByNumber
          • hmy_getBlockByHash
          • hmy_getBlocks
        • Contract Related Methods
          • hmy_estimateGas
          • hmy_getStorageAt
          • hmy_call
          • hmy_getCode
        • Protocol Related Methods
          • hmy_isLastBlock
          • hmy_epochLastBlock
          • hmy_latestHeader
          • hmy_getShardingStructure
          • hmy_blockNumber
          • hmy_syncing
          • hmy_gasPrice
          • net_peerCount
          • hmy_getEpoch
          • hmy_getLeader
        • Staking Related Methods
          • hmy_getCirculatingSupply
          • hmy_getTotalSupply
          • hmy_getStakingNetworkInfo
          • hmy_getAllValidatorInformation
          • hmy_getAllValidatorInformationByBlockNumber
          • hmy_getCurrentUtilityMetrics
          • hmy_getDelegationsByValidator
          • hmy_getDelegationsByDelegatorAndValidator
          • hmy_getDelegationsByDelegator
          • hmy_getValidatorMetrics
          • hmy_getMedianRawStakeSnapshot
          • hmy_getElectedValidatorAddresses
          • hmy_getAllValidatorAddresses
          • hmy_getCurrentStakingErrorSink
          • hmy_getValidatorInformation
          • hmy_getValidators
          • hmy_getSignedBlocks
          • hmy_isBlockSigner
          • hmy_getBlockSigners
        • Tracing Methods
          • trace_block
          • trace_transaction
      • Sample Code
    • Tools
      • Harmony VRF
      • The Graph
      • Envio
      • Ganache
        • Harmony Ganache
      • Harmony-React
      • Oracles
        • Band Protocol
      • Smart Contract Verification
    • Tutorials
      • Deploying HRC20
      • Deploying HRC721/NFT
      • The Graph - Subgraphs
        • Building & Deploying Subgraph (local node)
      • Using Band Oracle
      • Using Crosschain API
        • Scripts
        • Testing
        • Webserver
      • Using Web3.py & Pyhmy
      • Using IPFS & Filecoin
        • Using IPFS
        • Using NFT.storage
      • Indexing HRC20 with Envio
      • Building a Simple Metaverse Contract
      • Building a Simple Bridge with Ethereum
      • Staking for Multisig
    • DApp Examples
      • DApp Samples
      • Games
        • Harmony Puzzle
      • Cross-Chain
      • DeFi
      • Hackathons
        • DevPost
        • Hack the Horizon
      • Others
    • Wallets
      • Metamask
        • Interacting With Metamask
        • Using Metamask with Harmony Smart Contracts
        • Add or Switch to Harmony chain on Metamask
      • Harmony Chrome Extension Wallet
      • Math Wallet
      • WalletConnect
    • Harmony Stack and Projects
  • 🌏Network
    • Governance
      • Network Governance
        • Voting via Governance App
        • Voting via HMY CLI
      • HRC-20 Governance
      • FAQ
    • Validators
      • Terms & Concepts
        • Validator, BLS key, Instance
          • Shard Assignment
        • Slots Bidding and Election
        • Effective Proof-of-Stake
        • Block Reward
        • Epoch Transition
        • Slashing
        • Undelegation
      • Server Setup
        • Requirements
        • Cloud Guides
          • Digital Ocean
          • Vultr
          • AWS
          • Google Cloud
        • Raspberry Pi Guide
      • Node Setup
        • 1. HMY CLI Download
        • 2. Setting up BLS Keys
        • 3. Syncing DB
        • 4. Installing & Updating
          • Installing A Node
            • Using Node Binary
            • (Deprecated) Using AutoNode
              • Install & Run
              • Update
              • Monitor
              • BLS Key Management
              • Collect Rewards
              • Maintenance
              • Troubleshoot
              • Extra
            • (deprecated) Using Node.sh
          • Upgrading A Node
            • Using Node Binary
            • Using AutoNode (deprecated)
            • Using Node.sh (deprecated)
          • Checking A Node
      • Creating A Validator
      • Managing A Validator
        • Checking Validator Information
        • Changing Validator Information
        • Delegating To A Validator
        • Undelegating From A Validator
        • Check Your Delegations
        • Collecting Rewards
        • Adding A Validator Logo
      • Staking Dashboard Basics
      • Validator Information Terms
      • Validator Security Tips
      • Slashing and Uptime
      • Monitoring
        • Node Sync
        • Prometheus & Grafana
        • Network Status
      • Troubleshooting
        • Why am i not Elected?
        • Frequently Asked Questions (FAQ)
      • Tools
        • Telegram Bots
        • Dashboards
        • Reward Calculators
        • Text User Interface (TUI)
        • HMY Bidder
        • Mobile Apps
          • One Validator Dashboard
          • Termux
    • Delegators
      • Introduction
      • Staking
        • Via Browser
          • Staking Dashboard
          • Staking Transactions
          • Sending Transactions
        • Via Mobile
        • FAQ
      • Redelegation
      • Informational Videos
Powered by GitBook
On this page
  • Overview
  • Sending a transaction
  • Checking the transaction hash
  • Detail
  • ChainIDs
  • Our first transaction
  • Result of the transaction

Was this helpful?

Export as PDF
  1. General
  2. Ecosystem
  3. Wallets
  4. HMY CLI (Harmony Command Line Interface)

Sending Transactions

Perhaps the most important feature of the hmy CLI is the ability to create and send signed transactions to the Harmony blockchain.

Overview

Sending a transaction

Using the Binary:

./hmy transfer --node="<endpoint-address>" \
 --from <ONE_address> --to <ONE_address> \
 --from-shard <shard> --to-shard <shard> \
 --amount <amount> --chain-id <chain-id> --passphrase

Using the Shell Wrapper:

./hmy.sh -- transfer --node="<endpoint-address>" \
 --from <ONE_address> --to <ONE_address> \
 --from-shard <shard> --to-shard <shard> \
 --amount <amount> --chain-id <chain-id> --passphrase

Example:

./hmy --node="https://api.s0.t.hmny.io" \
 transfer --from one1yc06ghr2p8xnl2380kpfayweguuhxdtupkhqzw \
 --to one1q6gkzcap0uruuu8r6sldxuu47pd4ww9w9t7tg6 \    
 --from-shard 0 --to-shard 1 --amount 12.5 --chain-id mainnet --passphrase mypassword

Checking the transaction hash

Check for finality of the transaction by using the transaction hash like so:

Using the Binary:

./hmy blockchain transaction-receipt <transaction_id> --node="<endpoint-address>"

Using the Shell Wrapper:

./hmy.sh -- blockchain transaction-receipt <transaction_id> --node="<endpoint-address>"

Example:

./hmy --node="https://api.s0.t.hmny.io" \
 blockchain transaction-receipt \
 0x599793f313ee17566f8d09728b9d043b8e26135ddce86beeee13f98767d452f7

Detail

ChainIDs

Let's first check what chain-ids are available for us to use, we can do that easily with:

Using the Binary:

./hmy blockchain known-chains

Using the Shell Wrapper:

./hmy.sh -- blockchain known-chains

Example:

./hmy blockchain known-chains

[
  "mainnet",
  "testnet",
  "devnet"
]

Notice that the output is pretty printed JSON, most outputs of hmy are JSON encoded and hmy defaults to showing it nicely indented. Sometimes though you might want to turn that off, you can do that for any command with the flag --no-pretty.

By default, hmy assumes the testnet chain-id; override that with the --chain-id flag

Our first transaction

We'll use the transfer subcommand of hmy to send a transaction.

./hmy transfer
Error: required flag(s) "amount", "from", "from-shard", "to", "to-shard" not set

Notice that simply invoking the transfer subcommand gave us an error message about certain flags not being set. We'll need to provide legitimate values for these flags for our transaction to proceed successfully. Reading off the flags in the error message from left to right, the semantic meanings are as follows:

  • amount: The quantity of Harmony One token to transfer from the senders to the receiver

  • from: The sender's one address

  • from-shard: Shard from which sender's balance will be drawn from

  • to: Receiver's ONE address

  • to-shard: Shard in which receiver will receive the amount sent by the sender

  • passphrase: your wallet passphrase, which is prompted when you hit enter (or you can use a txt file with password and add it: --passphrase file.txt)

A sharded blockchain is a new kind of blockchain architecture where the network is partitioned into sub-networks called shards. Sharding is one of the distinguishing features of Harmony and it is key to solving the traditional scalability problems encountered in other blockchain protocols.

Note: The same ONE address will have a different balance in each shard. Currently Harmony mainnet has four shards while testnet has three shards. Sending a transaction from one shard to another is called a "cross-shard transaction."

Thus, a correct usage of transfer looks like:

Using the Binary:

./hmy transfer --node="<endpoint-address>" \
 --from <ONE_address> --to <ONE_address> \
 --from-shard <shard> --to-shard <shard> \
 --amount <amount> --chain-id <chain-id> --passphrase

Using the Shell Wrapper:

./hmy.sh -- transfer --node="<endpoint-address>" \
 --from <ONE_address> --to <ONE_address> \
 --from-shard <shard> --to-shard <shard> \
 --amount <amount> --chain-id <chain-id> --passphrase

Example:

./hmy transfer --node="https://api.s0.t.hmny.io" \
 --from one1yc06ghr2p8xnl2380kpfayweguuhxdtupkhqzw \
 --to one1q6gkzcap0uruuu8r6sldxuu47pd4ww9w9t7tg6 \
 --from-shard 0 --to-shard 1 --amount 10 --chain-id mainnet
{"transaction-receipt":"0x455f98a3aa11ef50ee5cc5ac8bbd79e04f2fe353180bb7e25fc6c921fc8fdc83"}

hmy assumes that the private keys needed for signing the transaction on behalf of the sender (one1yc06ghr2p8xnl2380kpfayweguuhxdtupkhqzw in this example) exist in the local keystore or in the hardware wallet if the --ledger flag was used.

The sender's account must have enough of a balance on the from-shard to send a transaction. In our example,one1yc06ghr2p8xnl2380kpfayweguuhxdtupkhqzw must have an amount balance of at least 10 in shard 0.

Try out your transaction with the flag --dry-run, this flag tells hmy to create, cryptographically sign the transaction but not actually send it off. Sender's balances are checked and the output is a JSON dump of the signed transaction.

Signing and sending a transaction is very quick, about 2 seconds maximum. The actual sending of the transaction is done via an RPC (Remote Procedure Call), you'll notice that we did not explicitly say where to send the transaction to. This is because the default destination of the RPC call goes to http://localhost:9500, the default HTTP RPC server running when you start a local harmony blockchain. For real world usage though, you'll want a different location. You can control that with the --node flag (see the top of this page for an example).

Result of the transaction

Once an RPC machine receives a transaction, it sends you back a transaction hash. This transaction hash is the key identifier used when querying the blockchain for transactions.

Simply having a transaction hash does NOT imply that the transaction was successfully accepted by the blockchain. A transaction is successfully accepted once it has been added to the blockchain. In the case of cross-shard transactions (when the from-shard, to-shard values are different), this means each shard has added the transaction to their blockchain.

We can pull down details of the finalized transaction with ./hmy blockchain transaction-receipt as well:

Using the Binary:

./hmy blockchain transaction-receipt --node="<endpoint-address>" <transaction-hash>

Using the Shell Wrapper:

./hmy.sh -- blockchain transaction-receipt --node="<endpoint-address>" <transaction-hash>

Example:

./hmy blockchain transaction-receipt \
    --node="https://api.s0.t.hmny.io" \
    0x25dd32397b5a69146b2dc3bbdc8ef8aae271e9b12a36c6dff1eb8995cac9dcba
{
  "id": "0",
  "jsonrpc": "2.0",
  "result": {
    "blockHash": "0x67eb5d671af76814d9ab326f9ec36c5b889b872e0c34e8cbe484aea20f0611ea",
    "blockNumber": "0x21017f",
    "contractAddress": null,
    "cumulativeGasUsed": "0x5208",
    "from": "one1sp4q22r7cc78742mzrufu6xwcekqxjgq78jk3m",
    "gasUsed": "0x5208",
    "logs": [],
    "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
    "shardID": 0,
    "status": "0x1",
    "to": "one129r9pj3sk0re76f7zs3qz92rggmdgjhtwge62k",
    "transactionHash": "0x25dd32397b5a69146b2dc3bbdc8ef8aae271e9b12a36c6dff1eb8995cac9dcba",
    "transactionIndex": "0x0"
  }
}

If the transaction has not finalized then the "result" key in the JSON output will have value of null.

You can tell hmy to wait until transaction confirmation by providing a positive integer value to flag --wait-for-confirm. For example, --wait-for-confirm=10 will try checking the receipt of the transaction for 10 seconds.

PreviousCreate or Import WalletNextStaking Transactions

Last updated 4 years ago

Was this helpful?

You should set the value of --node to the same shard that sent the transaction, notice that the URL we used, https://api.s0.t.hmny.io contained s0, this means that this URL is targeting shard 0. For further information, see .

🎶
Querying the Blockchain