Skip to content

User Setup, Transaction preparation for Sales Order and Submit a Transaction

To set up a user in the CMS, prepare a transaction for a sales order, and then submit it, follow these steps:

Setting Up a User:

  • First, you need to initialize the TradeCms instance with the base URL of your CMS.
  • Then, you can set up a user using a mnemonic phrase and a signer option (either "vault" or "aws"). Here is an example of how to do this:
javascript
import { TradeCms } from "skc-trade-sdk";
const cms = new TradeCms("https://example.com");

// User setup with Vault Signing
const userVault = await cms.setupUser(
  "liar spend east depth advice float punch grace cigar angle pulse soup", 
  "vault"
);

// User setup with AWS Signing
const userAws = await cms.setupUser(
  "mnemonic-phrase-here", 
  "aws"
);

This sets up the user with the specified mnemonic and signer option.

Preparing a Transaction for a Sales Order:

  • After setting up the user, you need to prepare a transaction for a sales order. This involves specifying the method name, arguments, sales order ID, and an optional memo. Here is an example:
javascript
import { TradeCms } from "skc-trade-sdk";
const cms = new TradeCms("https://example.com");

const preparedSalesOrderTx = await cms.prepareTxSalesOrder(
  "methodName",
  { arg1: "value1", arg2: "value2" },
  "sales-order-id",
  "Optional memo"
);

This prepares the transaction for the specified sales order.

Submitting the Transaction:

  • Once the transaction is prepared, you need to sign it and then submit it. Here is an example of how to sign and submit the transaction:
javascript
import { TradeCms } from "skc-trade-sdk";
const cms = new TradeCms("https://example.com");

const txData = {
  from: "0xSenderAddress",
  to: "0xRecipientAddress",
  data: "encoded-transaction-data",
  nonce: "0",
  gasLimit: "100000",
  chainId: "31337",
  offset: "optional-offset"
};

// Sign the transaction
const signedTx = await cms.signTx(txData);

// Submit the signed transaction
const txHash = await cms.submitTx(signedTx);

This signs the prepared transaction and then submits it to the blockchain.

By following these steps, you can set up a user, prepare a transaction for a sales order, and submit it using the CMS.