# js-circle-chain-sdk **Repository Path**: lidh04/js-circle-chain-sdk ## Basic Information - **Project Name**: js-circle-chain-sdk - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-08-29 - **Last Updated**: 2024-12-28 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # circle-chain sdk in javascript The javascript sdk for circle-chain. ## User module The module provides the user services. ## Wallet module The module provides the wallet service. ## Block module The module provides the block service. ## install ```javascript npm i @lidh04/circle-chain-sdk ``` ## Usage ### First register and login or login with verify code ```javascript // 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. ``` ### Create wallet ```javascript const response = await createWallet(); if (response.status !== 200) { throw new Error(response.message); } const { data: address } = response; console.log("create wallet success, address:", address); ``` ### Mine Block locally Using your address, mine the block locally in your machine, and get the cc coins now! When you success upload one block, you will get `10cc`(`100,000li`) in your address. ```js import os from "os"; import sdk from '@lidh04/circle-chain-sdk'; const { miner } = sdk; async function main() { if (!miner.canMineBlock()) { return; } const address = '15ea379mhPvKG95T3MnoCy9xuvTpusnXYx'; // replace your address here! const response = await miner.fetchMyBlockData(address); console.log("fetchMyBlockData response:", JSON.stringify(response)); const { status, data } = response; if (status === 200 && data) { const { blockHeaderHexString, channelId } = data; const cpus = os.cpus(); console.log("find the cpu cores:", cpus.length); const result = await miner.mineBlock(blockHeaderHexString, cpus.length - 1); console.log("mineBlock result:", JSON.stringify(result)); if (result) { const items = result.split("\n"); console.log(result); const minedBlockHeader = items[0]; const postResult = await miner.postMyBlock({ address, channelId, blockHeaderHexString: minedBlockHeader }); console.log("post mined block result:", JSON.stringify(postResult)); } } } main().catch(err => console.error(err)); ``` ### Set pay password ```javascript 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. ``` ### Transactions ```javascript 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. ``` ### Add contacts ```javascript 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. ``` ## versions ### 1.0.22 - improve the sdk security. ### 1.0.21 - fix some bugs. ### 1.0.20 - support mine block locally