Skip to content

Main Capabilities of TradeCms

The TradeCms class provides various capabilities for interacting with a Content Management System (CMS), handling Ethereum transaction signing, and managing data. Here are the main capabilities and some examples:

Login

The login method allows users to log into the CMS using either API keys or email/password credentials.

  • Example:
    typescript
    import { TradeCms } from "skc-trade-sdk";
    const cms = new TradeCms("https://example.com");
    // Use API-Key for login
    await cms.login({ apiKey: "your-api-key" });
    // Use Email and Password for login
    await cms.login({ email: "admin@example.com", password: "your-password" });

Create Records

The create method allows creating new records in a CMS collection.

  • Example:
    typescript
    import { TradeCms } from "skc-trade-sdk";
    const cms = new TradeCms("https://example.com");
    const newRecord = await cms.create("transactions", {
      hash: "0x7d2bb304d51b99e614ac8f953f54d8aa3b2cc388a598efe00b86ce2bf0431aaa",
      action: "transfer",
      memo: "Sample transaction memo",
      sender: "6731f8377c28366067c4d505"
    });

Read Records

The read method allows reading records from a CMS collection with optional query parameters.

  • Example:
    typescript
    import { TradeCms } from "skc-trade-sdk";
    const cms = new TradeCms("https://example.com");
    const records = await cms.read("transactions", "limit=10");

Update Records

The update method allows updating an existing record in the CMS.

  • Example:
    typescript
    import { TradeCms } from "skc-trade-sdk";
    const cms = new TradeCms("https://example.com");
    const updatedRecord = await cms.update("transactions", 
      { memo: "Updated transaction memo" }, 
      "record-id-to-update"
    );

Delete Records

The delete method allows deleting a record in the CMS by ID.

  • Example:
    typescript
    import { TradeCms } from "skc-trade-sdk";
    const cms = new TradeCms("https://example.com");
    await cms.delete("transactions", "record-id-to-delete");

Setup User

The setupUser method sets up a CMS user using a mnemonic and a signer option (e.g., "vault" or "aws").

  • Example:
    typescript
    import { TradeCms } from "skc-trade-sdk";
    const cms = new TradeCms("https://example.com");
    // User setup with Vault Signing
    const user = await cms.setupUser(
      "liar spend east depth advice float punch grace cigar angle pulse soup", 
      "vault"
    );
    // User setup with AWS Signing
    const user = await cms.setupUser(
      "mnemonic-phrase-here", 
      "aws"
    );

Prepare Transactions

The prepareTxTradeToken and prepareTxTokenExchange methods prepare transactions for trade token operations and token exchange operations, respectively.

  • Example for Trade Token:
    typescript
    import { TradeCms } from "skc-trade-sdk";
    const cms = new TradeCms("https://example.com");
    await cms.prepareTxTradeToken(
      "methodName",
      { arg1: "value1", arg2: "value2" },
      "trade-token-id",
      "Optional memo"
    );
  • Example for Token Exchange:
    typescript
    import { TradeCms } from "skc-trade-sdk";
    const cms = new TradeCms("https://example.com");
    const preparedExchangeTx = await cms.prepareTxTokenExchange(
      "methodName",
      { arg1: "value1", arg2: "value2" },
      "token-exchange-id",
      "Optional memo"
    );

Create Trade Token

The createTradeToken method creates a new trade token.

  • Example:
    typescript
    import { TradeCms } from "skc-trade-sdk";
    const cms = new TradeCms("https://example.com");
    const tradeToken = await cms.createTradeToken(
      "MyTradeToken",
      "category-name",
      "item-123",
      "USD",
      "Mintable",
      "1000000",
      "Optional memo"
    );

Create Token Exchange

The createTokenExchange method creates a new token exchange.

  • Example:
    typescript
    import { TradeCms } from "skc-trade-sdk";
    const cms = new TradeCms("https://example.com");
    const tradeToken = await cms.createTokenExchange(
      "MyTokenExchange",
      "offset-value",
      "https://example.com/custody",
      "Mintable",
      "Optional memo"
    );

Sign and Submit Transactions

The signTx and submitTx methods sign and submit Ethereum transactions using the CMS KMS.

  • Example:
    typescript
    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"
    };
    const signedTx = await cms.signTx(txData);
    const submit = await cms.submitTx(signedTx);

These examples illustrate the primary capabilities of the TradeCms class, showcasing its versatility in managing CMS records, handling user setup, preparing and executing transactions, and more.