Skip to content
First Access Exchange

Transactions

Transactions are Cosmos SDK transactions, signed in SIGN_MODE_DIRECT with a secp256k1 key, for the chain id firstaccess-testnet-1. Any Cosmos client can build them; dYdX's clients also know the dydxprotocol messages.

Keys

A dydx-prefixed address from a BIP-39 phrase on m/44'/118'/0'/0/0:

import { BECH32_PREFIX, LocalWallet } from '@dydxprotocol/v4-client-js';
 
async function main() {
  const wallet = await LocalWallet.fromMnemonic(process.env.MNEMONIC!, BECH32_PREFIX);
  console.log(wallet.address);
}
 
main();

An address exists on chain once it has received something (the faucet's drip, for example); until then it has no account number and can't sign.

Account number and sequence

Every transaction is signed over the account's number and its sequence, which increases by one with each transaction in a block. Read both from /cosmos/auth/v1beta1/accounts/{address}.

  • Short-term orders and cancels don't use the sequence: they are replay-protected by their good_til_block. Send as many as you like at the account's current sequence.
  • Everything else (long-term and conditional orders, their cancels, transfers) must carry the next sequence. A transaction sent before the previous one is in a block must carry the sequence after it, or CheckTx refuses it with "account sequence mismatch". dYdX's clients read the sequence from the chain before each send, so wait for a transaction's block before sending the next (the examples do).

Gas and fees

TransactionGasFee
Only x/clob messages (place, cancel, batch cancel)Free, infinite meterNone: send an empty fee with gas 0 or any limit
Anything elseSimulate (/cosmos/tx/v1beta1/simulate) and add a margin (× 1.5)Gas × 25,000,000,000 adv4tnt, or × 0.025 micro-USDC in the chain's USDC denom

The node's minimum gas prices are 25000000000adv4tnt and 0.025 of the USDC denom (/dydxprotocol/assets/asset/0).

dYdX's Python client (dydx_v4_client 1.1.6) pays fees in NodeConfig.usdc_denom and prices gas only for dYdX's own USDC denom, so with ours it raises "is not a valid Denom". Pay fees in the chain token instead: node.builder.denomination = "adv4tnt" after NodeClient.connect (the examples do). The TypeScript client (@dydxprotocol/v4-client-js 3.6.0) takes the USDC denom from ValidatorConfig and works as it is.

Broadcasting

Broadcast the signed bytes with the RPC's broadcast_tx_sync (CheckTx's answer: code 0 means accepted into the mempool) or broadcast_tx_commit (waits for the block), or REST POST /cosmos/tx/v1beta1/txs with BROADCAST_MODE_SYNC. Then poll the RPC's tx method (or REST GET /cosmos/tx/v1beta1/txs/{hash}) until the transaction is in a block, and check its code. A short-term order's transaction is never in a block: it lives in the validators' memory, and only its fills reach a block. Follow it through the indexer.

dYdX's TypeScript client broadcasts short-term orders with broadcast_tx_sync, long-term and conditional orders with broadcast_tx_commit, and everything else with broadcast_tx_sync. The Python client broadcasts with gRPC BROADCAST_MODE_SYNC and returns CheckTx's answer without raising on a non-zero code: check tx_response.code.

Errors

A refused transaction's raw_log names the module and error, for example Order subticks 1010000 exceed the price cap (1000000 subticks) of CHAIN_MARKET_KIND_BINARY clob pair 1 or builder code fee ppm '20000' must be in the range (0, 10000]. x/binary's errors are listed in the x/binary reference.

Messages

MessageType URLSigner
Place an order/dydxprotocol.clob.MsgPlaceOrderthe subaccount's owner
Cancel an order/dydxprotocol.clob.MsgCancelOrderthe subaccount's owner
Cancel short-term orders in a batch/dydxprotocol.clob.MsgBatchCancelthe subaccount's owner
Deposit into a subaccount/dydxprotocol.sending.MsgDepositToSubaccountthe sender
Withdraw from a subaccount/dydxprotocol.sending.MsgWithdrawFromSubaccountthe subaccount's owner
Transfer between subaccounts/dydxprotocol.sending.MsgCreateTransferthe sender subaccount's owner
Send tokens/cosmos.bank.v1beta1.MsgSendthe sender
Halt, resolve, hand on a market, event or company/dydxprotocol.binary.Msg*its admin or governance (x/binary reference)

None of these messages changed in this fork, so dYdX's published protos and clients encode them correctly (open source).