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
  • Endpoints
  • POST /swap
  • POST /swap/bridge-in
  • POST /swap/viper
  • POST /swap/bridge-out
  • Local Endpoints
  • POST /local/swap
  • POST /local/swap/bridge-in
  • POST /local/swap/viper
  • POST /local/swap/bridge-out

Was this helpful?

Export as PDF
  1. Developers
  2. Tutorials
  3. Using Crosschain API

Webserver

This is a webserver using node and express, in order to start it you need to run the following commands in the terminal:

  • npm install

  • node index.js

We assume that it will run in port 3000 but feel free to change it. Don't forget to update the scritps accordingly though.

Endpoints

The general architecture of the API is the following

  • Endpoints that receive signed transactions as inputs and they will complete the required transactions. This allow you to sign the transactions of the front end and it is safe to use on a production server because the private key is never sent to the endpoints. To sign the transactions you can see the examples in the scripts folder of this repo.

  • You can make and end-to-end swap using the /swap endpoints. But this is a multi-step process that will fail if one of the single steps fails. It uses Harmony's Horizon Bridge and Viper DEX, so for example, the bridging part can work but if there is no liquidity in the pool so the who transaction will fail. Therefore use this enpoint only if you are sure that Viper's LPs have enough liquidity.

  • If you prefer to do it setp-by-step, you should use the following end-points in the specified order:

    • /swap/bridge-in - Bridges BUSD in ethereum to Harmony's BUSD

    • /swap/viper/ - Swaps Harmony's BUSD to bscBUSD (Both are bridged assets in the Harmony network)

    • /swap/bridge-out - Bridges bscBUSD into Binance's BUSD

Right now the following endpoints are enabled, but we will keep adding more reguarly, so remember to pull once in a while.

POST /swap

This endpoint will swap balances between Ethereum BUSD and Binance BUSD, the body for this request should look like this:

{
    "amount" : amount,
    "oneAddress" : oneAddress,
    "ethAddress" : ethAddress
    "lockApproveTxnHash" : approveTxnHash
    "lockTxnHash" : lockTxnHash
    "burnApproveTxnHash" : approveTxnHash
    "depositTxnHash" : depositTxnHash
    "burnTxnHash" : burnTxnHash
    "routerContract" : routerContract
    "fromTokenContract" : fromTokenContract
}
{ 
    trx: "swap", 
    success: bool, 
    error_message: message, 
    error_body: body
}
  • amount: this is a string with the amount in decimals (e.g. "10.50") that you want to swap

  • oneAddress: this is a string with the address of the wallet owned by the private key in the Harmony wallet format i.e. oneaxxxxxxxx

  • ethAddress: this is a string with the address of the wallet owned by the private key in the Ethereum wallet format i.e. Oxaxxxxxxxx

  • lockApproveTxnHash : this is a string with the hash of the contract manager's approval for the lock transaction

  • lockTxnHash : this is a string with the hash of the lock transaction

  • burnApproveTxnHash : this is a string with the hash of the contract manager's approval for the burn transaction

  • depositTxnHash : this is a string with the hash of the deposit transaction

  • burnTxnHash : this is a string with the hash of the burn transaction

  • routerContract : This is a string with the writing approval for Viper's swap router contract

  • fromTokenContract : This is a string with the transaction approval for the account swapping in Viper

POST /swap/bridge-in

This enpoint will bridges BUSD in ethereum to Harmony's BUSD, it is the first step of the step-by-step swap, the body for this request should look like this:

{
    "amount" : amount,
    "oneAddress" : oneAddress,
    "ethAddress" : ethAddress,
    "lockApproveTxnHash" : approveTxnHash,
    "lockTxnHash" : lockTxnHash
}
{ 
    trx: "bridge", 
    success: bool, 
    error_message: message, 
    error_body: body
}
  • amount: this is a string with amount in decimals (e.g. "10.50") that you want to swap

  • oneAddress: the address of the wallet owned by the private key in the Harmony wallet format i.e. oneaxxxxxxxx

  • ethAddress: the address of the wallet owned by the private key in the Ethereum wallet format i.e. Oxaxxxxxxxx

  • lockApproveTxnHash : this is a string with the hash of the contract manager's approval for the lock transaction

  • lockTxnHash : this is a string with the hash of the lock transaction

POST /swap/viper

This enpoint will swap Harmony's BUSD to bscBUSD (Both are bridged assets in the Harmony network), it is the second step of the step-by-step swap, the body for this request should look like this:

{
    "amount" : amount,
    "oneAddress" : oneAddress,
    "ethAddress" : ethAddress
    "routerContract" : routerContract
    "fromTokenContract" : fromTokenContract
}
{ 
    trx: "viper", 
    success: bool, 
    error_message: message, 
    error_body: body
}
  • amount: this is a string with amount in decimals (e.g. "10.50") that you want to swap

  • wallet: this is the private key of the wallets with the funds, please use an .env or equivalent to store this key, never put it in your code

  • oneAddress: the address of the wallet owned by the private key in the Harmony wallet format i.e. oneaxxxxxxxx

  • routerContract : This is a string with the writing approval for Viper's swap router contract

  • fromTokenContract : This is a string with the transaction approval for the account swapping in Viper

POST /swap/bridge-out

{
    "amount" : amount,
    "oneAddress" : oneAddress,
    "ethAddress" : ethAddress,
    "burnApproveTxnHash" : approveTxnHash,
    "depositTxnHash" : depositTxnHash,
    "burnTxnHash" : burnTxnHash
}
{ 
    trx: "bridge", 
    success: bool, 
    error_message: message, 
    error_body: body
}
  • amount: this is a string with amount in decimals (e.g. "10.50") that you want to swap

  • oneAddress: the address of the wallet owned by the private key in the Harmony wallet format i.e. oneaxxxxxxxx

  • ethAddress: the address of the wallet owned by the private key in the Ethereum wallet format i.e. Oxaxxxxxxxx

  • burnApproveTxnHash : this is a string with the hash of the contract manager's approval for the burn transaction

  • depositTxnHash : this is a string with the hash of the deposit transaction

  • burnTxnHash : this is a string with the hash of the burn transaction

Local Endpoints

POST /local/swap

This enpoint will swap balances between Ethereum BUSD and Binance BUSD, the body for this request should look like this:

{
    "amount" : amount,
    "wallet" : wallet,
    "oneAddress" : oneAddress,
    "ethAddress" : ethAddress
}
{ 
    trx: "swap", 
    success: bool, 
    error_message: message, 
    error_body: body
}
  • amount: this is a string with amount in decimals (e.g. "10.50") that you want to swap

  • wallet: this is the private key of the wallets with the funds, please use an .env or equivalent to store this key, never put it in your code

  • oneAddress: the address of the wallet owned by the private key in the Harmony wallet format i.e. oneaxxxxxxxx

  • ethAddress: the address of the wallet owned by the private key in the Ethereum wallet format i.e. Oxaxxxxxxxx

POST /local/swap/bridge-in

This enpoint will bridges BUSD in ethereum to Harmony's BUSD, it is the first step of the step-by-step swap, the body for this request should look like this:

{
    "amount" : amount,
    "wallet" : wallet,
    "oneAddress" : oneAddress,
    "ethAddress" : ethAddress
}
{ 
    trx: "bridge", 
    success: bool, 
    error_message: message, 
    error_body: body
}
  • amount: this is a string with amount in decimals (e.g. "10.50") that you want to swap

  • wallet: this is the private key of the wallets with the funds, please use an .env or equivalent to store this key, never put it in your code

  • oneAddress: the address of the wallet owned by the private key in the Harmony wallet format i.e. oneaxxxxxxxx

  • ethAddress: the address of the wallet owned by the private key in the Ethereum wallet format i.e. Oxaxxxxxxxx

POST /local/swap/viper

This enpoint will swap Harmony's BUSD to bscBUSD (Both are bridged assets in the Harmony network), it is the second step of the step-by-step swap, the body for this request should look like this:

{
    "amount" : amount,
    "wallet" : wallet,
    "oneAddress" : oneAddress,
}
{ 
    trx: "viper", 
    success: bool, 
    error_message: message, 
    error_body: body
}
  • amount: this is a string with amount in decimals (e.g. "10.50") that you want to swap

  • wallet: this is the private key of the wallets with the funds, please use an .env or equivalent to store this key, never put it in your code

  • oneAddress: the address of the wallet owned by the private key in the Harmony wallet format i.e. oneaxxxxxxxx

POST /local/swap/bridge-out

This enpoint will bridges bscBUSD into Binance's BUSD, it is the third step of the step-by-step swap, the body for this request should look like this:

{
    "amount" : amount,
    "wallet" : wallet,
    "oneAddress" : oneAddress,
    "ethAddress" : ethAddress
}
{ 
    trx: "bridge", 
    success: bool, 
    error_message: message, 
    error_body: body
}
  • amount: this is a string with amount in decimals (e.g. "10.50") that you want to swap

  • wallet: this is the private key of the wallets with the funds, please use an .env or equivalent to store this key, never put it in your code

  • oneAddress: the address of the wallet owned by the private key in the Harmony wallet format i.e. oneaxxxxxxxx

  • ethAddress: the address of the wallet owned by the private key in the Ethereum wallet format i.e. Oxaxxxxxxxx

PreviousTestingNextUsing Web3.py & Pyhmy

Last updated 3 years ago

Was this helpful?

You can see an example of this call in the bridge_eth_to_one.js file in the of the repo

You can see an example of this call in the viper_swap.js file in the of the repo

You can see an example of this call in the bridge_one_to_bsc.js file in the of the repo

You can see an example of this call in the swap.js file in the of the repo

You can see an example of this call in the bridge-lock.js file in the of the repo

You can see an example of this call in the viper.js file in the of this repo

You can see an example of this call in the bridge-burn.js file in the of this repo

🏗️
scripts folder
scripts folder
scripts folder
testing folder
testing folder
testing folder
testing folder