Appearance
Create a TradeToken, Set up a Sales Order and Manage its Exchange
To demonstrate a complete workflow of creating a trade token, setting up a sales order, and managing its exchange, we will use the TradeCms
from the skc-trade-sdk
. Here are the steps involved:
Step 1: Initialize TradeCms
First, initialize the TradeCms
instance.
typescript
import { TradeCms } from "skc-trade-sdk";
const cms = new TradeCms("https://example.com");
Step 2: Login to TradeCms
Login using either an API key or email and password.
typescript
// 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" });
Step 3: Create a Trade Token
Create a new trade token using the createTradeToken
method.
typescript
const tradeToken = await cms.createTradeToken(
"MyTradeToken",
"category-name",
"item-123",
"USD",
"Mintable",
"1000000",
"Optional memo"
);
Step 4: Prepare Transaction for Trade Token
Prepare a transaction for the trade token.
typescript
await cms.prepareTxTradeToken(
"methodName",
{ arg1: "value1", arg2: "value2" },
"trade-token-id",
"Optional memo"
);
Step 5: Create a Sales Order
Create a sales order using the createSalesOrder
method.
typescript
const salesOrder = await cms.createSalesOrder(
"MySalesOrder",
"0xSellerAddress",
"https://example.com/sales-order",
"offset-value",
"Optional memo"
);
Step 6: Prepare Sales Order Transaction
Prepare a transaction for the sales order.
typescript
const preparedSalesOrderTx = await cms.prepareTxSalesOrder(
"methodName",
{ arg1: "value1", arg2: "value2" },
"sales-order-id",
"Optional memo"
);
Step 7: Fetch Sales Order Details
Fetch the details of the sales order.
typescript
const salesOrderDetails = await cms.salesOrderDetails("sales-order-id");
Step 8: Create Token Exchange
Create a token exchange for the sales order.
typescript
const tokenExchange = await cms.createTokenExchange(
"MyTokenExchange",
"offset-value",
"https://example.com/custody",
"Mintable",
"Optional memo"
);
Step 9: Prepare Token Exchange Transaction
Prepare a transaction for the token exchange.
typescript
const preparedExchangeTx = await cms.prepareTxTokenExchange(
"methodName",
{ arg1: "value1", arg2: "value2" },
"token-exchange-id",
"Optional memo"
);
Step 10: Fetch Token Exchange Details
Fetch the details of the token exchange.
typescript
const exchangeDetails = await cms.tokenExchangeDetails("exchange-id");
Step 11: Submit the Transaction
Submit the prepared transaction.
typescript
const txHash = await cms.submitTx(preparedExchangeTx);
This workflow covers the creation of a trade token, setting up a sales order, and managing its exchange using the TradeCms
from the skc-trade-sdk
.