codechain-credit-sdk
TypeScript icon, indicating that this package has built-in type declarations

1.0.0-rc0 • Public • Published

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);

Readme

Keywords

Package Sidebar

Install

npm i codechain-credit-sdk

Weekly Downloads

2

Version

1.0.0-rc0

License

ISC

Unpacked Size

8.1 kB

Total Files

5

Last publish

Collaborators

  • jjg_kodebox