codechain-credit-sdk
v1.0.0-rc0
Published
A JavaScript SDK for CodeChain Credit
Downloads
3
Readme
CodeChain Credit SDK for JavaScript
How to install
# npm
npm install codechain-credit-sdk
# yarn
yarn add codechain-credit-sdk
How to configure the API key
The SDK detects an environment variable and uses them for SDK requests. The environment variable that you set to provide your API key is:
CODECHAIN_CREDIT_API_KEY
Functions
- getAddress(): PlatformAddress
- signTransaction(Transaction): SignedTransaction
Example
const SDK = require("codechain-sdk");
const { getAddress, signTransaction } = require("codechain-credit-sdk");
async function main() {
const sdk = new SDK({
server: "https://rpc.codechain.io",
networkId: "cc"
});
const assetAddress = await sdk.key.createAssetAddress({ type: "P2PKH" });
const platformAddress = await getAddress();
const tx = sdk.core.createMintAssetTransaction({
scheme: {
shardId: 0,
metadata: {
name: "ABC Coin"
},
supply: 1000
},
recipient: assetAddress
});
tx.setSeq(await sdk.rpc.chain.getSeq(platformAddress));
tx.setFee(200000);
const signedTx = await signTransaction(tx);
const txhash = await sdk.rpc.chain.sendSignedTransaction(signedTx);
console.log(`Transaction sent: ${txhash.toString()}`);
}
main().catch(console.error);