dYdX Transaction Signing

To sign and broadcast the transaction to the dYdX network, follow these steps:

  1. Prepare unsigned transaction in Base64 encrypted format.

  2. Sign the transaction using the following code:

import { ImportableWallets, getSigningWallet } from '@stakekit/signers';
import { Networks } from '@stakekit/common';

async function main() {
  const walletoptions = {
    mnemonic:
      '***',
    walletType: ImportableWallets.Keplr,
    index: 0,
  };

  const signingWallet = await getSigningWallet(Networks.Dydx, walletoptions);
  const address = await signingWallet.getAddress();
  const additionalAddresses = await signingWallet.getAdditionalAddresses();

  console.log('My wallet additionalAddresses: ', additionalAddresses);
  console.log('My wallet address: ', address);

  const unsignedTransaction = '<unsgined transaction>';

  const signedTx = await signingWallet.signTransaction(unsignedTransaction);

  console.log('Signed transaction Tx (hex): ', signedTx);
}

(async () => {
  await main();
})();

Upon successful execution, the script prints the signed transaction in the hexadecimal format, ready to be broadcasted:

✅ Signed transaction Tx (hex): ...
  1. Broadcast the transaction to the dYdX network by sending a POST request to /api/v1/unified/transaction/broadcast.

What's Next?