Setup the dYdX CLI

dYdX CLI: Initial setup

Goal: build and setup dydxprotocold on your local MacOS machine, or a Windows machine with WSL, so you can access the dYdX Chain via the command line

Prerequisites

A MacOS machine - although a similar process may be deduced for another OS, so long as you install the necessary tools

1. Install Homebrew

Make sure you have Homebrew installed

brew --version

If not, execute

/bin/bash -c "$(curl -fsSL <https://raw.githubusercontent.com/Homebrew/install/HEAD/in

2. Get the tools

Make sure everything is up to date

brew update && brew upgrade 

You need git , make and go

 brew install make git [email protected]

3. Clone v4-chain git repository

Navigate to the directory under which you would like to clone the dYdX Chain source code into and execute the followin:

git clone https://github.com/dydxprotocol/v4-chain.git
cd v4-chain/protocol/

4. Checkout, build and install dydxprotocold

From within v4-chain/protocol/ directory

  1. First make sure your local repository is up to date

git fetch --prune && git pull

By default, your repository is at the latest, often not-yet released, version of the software (the main branch). You can check the tracked version with

$ git status
On branch main
Your branch is up to date with 'origin/main'.

nothing to commit, working tree clean
  1. Unless else is explicitly required, you should be using the latest released version. You can check which is it from this location. The one marked as latest is the latest released - at the time of writing, that is v3.0.0.To check out v3.0.0 run:

git checkout tags/protocol/v3.0.0

When opting for a different version, don’t forget to add tags/protocol/ before the version in the git checkout command

An output similar to the below works, if you switched from main branch to a released version:

$ git checkout tags/protocol/v3.0.0
Note: switching to 'tags/protocol/v3.0.0'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at 85fb10ad Upgrade cosmos fork to fix RPC queries (#956)
  1. Build the binary locally (might take some time)

LEDGER_ENABLED=true make install build

The created binary should be located at ./build/dydxprotocold - let’s make it available from everywhere

ln -sf "$(pwd)/build/dydxprotocold" /usr/local/bin

💡 While the step above can be executed multiple times safely, it’s only necessary to do so once.

💡 You may need to close and reopen your Terminal window, if this is the first time you perform these steps.

To test if all went well:

$ dydxprotocold version
3.0.0

5. Connect to dydx-mainnet-1

Set up an RPC node to connect to from the docs and configure it locally

dydxprotocold config node "https://dydx-dao-rpc.polkachu.com:443"

Configure the chain-id , so you don’t need to input it manually later

 dydxprotocold config chain-id dydx-mainnet-1

Connecting to Public Testnet dydx-testnet-4 can be done by simply using an RPC endpoint from the testnet docs - just make sure you add :433 at the end of the URL, e.g. https://testnet-dydx-rpc.lavenderfive.com:443 Don’t forget to configure chain-id too!

6. Test your connection to dydx-mainnet-1

Test by reading the balance of an address, for example dydx1y66c5c7zpcqxqgqec9ttutuwu60qkzav22h3ue

$ dydxprotocold query bank balances dydx1y66c5c7zpcqxqgqec9ttutuwu60qkzav22h3ue 
balances:
- amount: "22071848837500000000"
  denom: adydx
pagination:
  next_key: null
  total: "0"

8. dydxprotocold help

The dydxprotocold tool has a built in help menu - simply type the following to get information for any command

 dydxprotocold help [path to command] 

For example

$ dydxprotocold help query
Querying subcommands

Usage:
  dydxprotocold query [flags]
  dydxprotocold query [command]

Aliases:
  query, q

Available Commands:
  account                  Query for account by address
  assets                   Querying commands for the assets module
  auth                     Querying commands for the auth module
  bank                     Querying commands for the bank module
  block                    Get verified data for the block at given height
  blocktime                Querying commands for the blocktime module
  bridge                   Querying commands for the bridge module
  clob                     Querying commands for the clob module
  delaymsg                 Querying commands for the delaymsg module
  distribution             Querying commands for the distribution module
  epochs                   Querying commands for the epochs module
  evidence                 Query for evidence by hash or for all (paginated) submitted evidence
  feegrant                 Querying commands for the feegrant module
  feetiers                 Querying commands for the feetiers module
  gov                      Querying commands for the governance module
  ibc                      Querying commands for the IBC module
  ibc-transfer             IBC fungible token transfer query subcommands
  interchain-accounts      IBC interchain accounts query subcommands
  params                   Querying commands for the params module
  perpetuals               Querying commands for the perpetuals module
  prices                   Querying commands for the prices module
  rewards                  Querying commands for the rewards module
  sending                  Querying commands for the sending module
  slashing                 Querying commands for the slashing module
  staking                  Querying commands for the staking module
  stats                    Querying commands for the stats module
  subaccounts              Querying commands for the subaccounts module
  tendermint-validator-set Get the full tendermint validator set at given height
  tx                       Query for a transaction by hash, "<addr>/<seq>" combination or comma-separated signatures in a committed block
  txs                      Query for paginated transactions that match a set of events
  upgrade                  Querying commands for the upgrade module
  vest                     Querying commands for the vest module

Flags:
      --chain-id string   The network chain ID
  -h, --help              help for query

Global Flags:
      --home string         directory for config and data (default "/Users/kaizhang/.dydxprotocol")
      --log_format string   The logging format (json|plain) (default "plain")
      --log_level string    The logging level (trace|debug|info|warn|error|fatal|panic) (default "info")
      --trace               print out full stack trace on errors

Use "dydxprotocold query [command] --help" for more information about a command.

$ dydxprotocold help query bank
Querying commands for the bank module

Usage:
  dydxprotocold query bank [flags]
  dydxprotocold query bank [command]

Available Commands:
  balances           Query for account balances by address
  denom-metadata     Query the client metadata for coin denominations
  send-enabled       Query for send enabled entries
  spendable-balances Query for account spendable balances by address
  total              Query the total supply of coins of the chain

Flags:
  -h, --help   help for bank

Global Flags:
      --chain-id string     The network chain ID
      --home string         directory for config and data (default "/Users/kaizhang/.dydxprotocol")
      --log_format string   The logging format (json|plain) (default "plain")
      --log_level string    The logging level (trace|debug|info|warn|error|fatal|panic) (default "info")
      --trace               print out full stack trace on errors

Use "dydxprotocold query bank [command] --help" for more information about a command.

Last updated