README

SDK Reference Document

CDS SDK provides easy-to-use APIs for developers to set up a CDS trading platform that is ready to use.

Quick start

First, use NPM to install the SDK

npm install --save derivstudio/cds-sdk

Then, if you are not access via a Web browser, follow below steps:

import EthersFactory from "./factory/ethersFactory";
import { safeTransferFrom } from "./ticket";
const env = 'local';
const endpoint = 'https://demo.cleardao.com/api/';
const rpc = 'http://0.0.0.0:8545';
const privateKey = '0xa65044fecbaf8dc0b854bcc7c1503210e8aa2d644e93cacef0732ae779661a17';
let amount = 1;
let tokenId = 2;
let from = "";
let to = "";
let transaction = safeTransferFrom( from,to, tokenId, amount, Buffer.from(''));
let sdk = new EthersFactory(env, endpoint, rpc, privateKey);
try {
let hash = sdk.call(transaction);
console.log({ hash });
} catch (err) {
console.log(err);
}

If you access via a Web browser, you can just use the Metamask Wallet:

import MetaMaskFactory from "./factory/metaMaskFactory";
import { safeTransferFrom } from "./ticket";
const env = 'local';
const endpoint = 'https://demo.cleardao.com/api/';
const ethereum = window.ethereum;
let sdk = new MetaMaskFactory(env, endpoint,ethereum );
let amount = 1;
let tokenId = 2;
let from = "";
let to = "";
let transaction = safeTransferFrom( from,to, tokenId, amount, Buffer.from(''));
try {
let hash = await sdk.call(transaction);
console.log({ hash });
} catch (err) {
console.log(err);
}

After completing steps mentioned above, submit the transaction and confirm its status:

try {
        let hash = sdk.callConfirm(transaction);
        console.log({ hash });
    } catch (err) {
        console.log(err);
    }

Env

For switching environments, env switches contracts for different environments, corresponding to scr/config/contracts. $ {env} .ts, with the option local, kcctest.

Rpc

The rpc is the access to blockchain node address, such as ethereum use node https : //mainnet.infura.io/v3/

Transaction

Transaction is the requested transaction content that can be generated by encapsulated functions. Obtained from the transaction generation function below:

Last updated