CircleChain的Javascrip SDK

安装指南

use npm tool to install the sdk:

npm i @lidh04/circle-chain-sdk

使用指南

首先注册登录或验证码登录

// 1. you can register your account or just login with verify code
// option 1: register and then login:
const response = await sendRegisterVerifyCode({
    email: "test@gmail.com"
});
if (response.status !== 200) {
    throw new Error(response.message);
}
//receive the verify code for register.
const regResponse = await register({
    email: "test@gmail.com",
    passwordInput1: "1111111",
    passwordInput2: "1111111",
    verifyCode: "2222222"
});
if (regResponse.status !== 200) {
    throw new Error(regResponse.message);
}
// register success now. then you can login with password.
const loginResponse = await login({
    email: "test@gmail.com",
    password: "111111",
});
if (loginResponse.status !== 200) {
    throw new Error(loginResponse.message);
}
// option2: login with verify code without register.
const loginVerifyResponse = await sendVerifyCode({
    email: "test@gmail.com"
});
if (loginVerifyResponse.status !== 200) {
    throw new Error(loginVerifyResponse.message);
}
// receive the login verify code in your email.
const loginResult = await login({
    email: "test@gmail.com",
    verifyCode: "222222",
});
if (loginResult.status !== 200) {
    throw new Error(loginResult.message);
}
/// for your login, option1 and option2 are ok, you just select one.
// now you login success here.

创建钱包

const response = await createWallet();
if (response.status !== 200) {
    throw new Error(response.message);
}
const { data: address } = response;
console.log("create wallet success, address:", address);

设置支付密码

const response = await sendPayVerifyCode({
    email: 'test@gmail.com'
});
if (response.status !== 200) {
    throw new Error(response.message);
}
// receive the pay verify code in your email.
const setResponse = await setPayPassword({
    account: {
      email: "test@gmail.com",
    },
    verifyCode: '222222',
    password: '111111'
});
if (setResponse.status !== 200) {
    throw new Error(setResponse.message);
}
// now the pay password is set.

交易

const from = '1L8eRrBuWnBxcQ6DKCDkkPM7ozxDcmpho1';
const to = '14hF1BynFVnBEFKxyo51FHmJksVwfxg4sg';
// send asset from `1L8eRrBuWnBxcQ6DKCDkkPM7ozxDcmpho1` to `14hF1BynFVnBEFKxyo51FHmJksVwfxg4sg`
const response = await sendTo({
    email: 'test@gmail.com',
    from,
    address: to,
    transContent: {
        type: 1,
        uuid: 'e1f1d3c7-3c6e-4f3b-a50d-58710b851357'
    },
    payPassword: '111111'
});
if (response.status !== 200) {
    throw new Error(response.message);
}
// the asset is sent success.

// pay balance from `1L8eRrBuWnBxcQ6DKCDkkPM7ozxDcmpho1` to `14hF1BynFVnBEFKxyo51FHmJksVwfxg4sg`
response = await pay({
    from,
    to,
    value: 100,
    payPassword: "111111"
});
if (response.status !== 200) {
    throw new Error(response.message);
}
// the value is paid success.

添加联系方式

const response = await addContacts({
    email: "test2@gmail.com",
    name: "test2",
    sex: 1,
    address: "beijing"
});
if (response.status !== 200) {
    throw new Error(response.message);
}
// the contact is added success.

APIs

结点服务

  1. subcribe

  2. serverFeatures

  3. broadcastTransaction

用户和账号

  1. sendVerifyCode
  2. login
  3. logout
  4. sendRegisterVerifyCode
  5. register
  6. addContacts
  7. listContacts
  8. sendPayVerifyCode
  9. setPayPassword
  10. havePayPassword
  11. sendResetPasswordVerifyCode
  12. resetPassword
  13. saveOrUpdateUserInfo
  14. userInfo

钱包服务

云钱包

  1. createWallet
  2. listWallet
  3. getBalanceOfWallet
  4. getAssetsOfWallet
  5. getAssetsOfAddress
  6. getPublicKeyHashFromAddress
  7. getBalanceOfAddress
  8. sendTo
  9. pay
  10. searchTxByType
  11. searchTxByTime
  12. letMeTry

公共钱包

  1. public_getAddressByUid
  2. public_getAssetsOfAddress
  3. public_getBalanceOfAddress
  4. public_searchTransaction

区块服务

  1. getBlockHashList
  2. getBlock
  3. getBlockHeaderList
  4. getBockData
  5. getBlockTailsHashList
  6. getBlockTailsPO
  7. getTxByTxId
  8. searchTxByTxId
  9. searchTxByAddress
  10. searchUTXOs