io-creata-js
v1.0.1
Published
A JavasSript Open Source Library for signing and broadcasting transactions on creata
Downloads
10
Maintainers
Readme
This library provides supports for creata transaction signing and broadcasting.
Installation
In order to fully use this library, you need to run a local or remote full node and set up its rest server.
NPM
npm install io-creata-js
Yarn
yarn add io-creata-js
Browser Support
This version does not support browsers
Import
NodeJS
const ioCreata = require("io-creata-js");
Usage
- Generate address from mnemonic
const ioCreata = require("io-creata-js");
const chainId = "testnet";
const creata = ioCreata.network("YOUR_NODE_URL", chainId);
const mnemonic = "YOUR_SEED_PHRASE"
creata.setPath("m/44'/118'/0'/0/0"); //hd path for creata
const address = creata.getAddress(mnemonic);
const ecpairPriv = creata.getECPairPriv(mnemonic);
Generate ECPairPriv value that is needed for signing signatures
const ecpairPriv = creata.getECPairPriv(mnemonic);
Transfer cta to designated address.
- Make sure to input proper type, account number, and sequence of the creata account to generate StdSignMsg. You can get those account information on blockchain
creata.getAccounts(address).then(data => {
let stdSignMsg = creata.newStdMsg({
msgs: [
{
type: "creata-sdk/MsgSend",
value: {
amount: [
{
amount: String(100), // 6 decimal places ( 1 cta = 1000000fcta)
denom: "fcta" // coin denomination is fcta
}
],
from_address: address,
to_address: "creata1da4v3fxy3xkkgqr5g60cjmcpvjcjdd5e4m0qwa"
}
}
],
chain_id: chainId,
fee: { amount: [ { amount: String(20000), denom: "fcta" } ], gas: String(200000) },
memo: "creata_test_memo",
account_number: String(data.result.value.account_number),
sequence: String(data.result.value.sequence)
});
const signedTx = creata.sign(stdSignMsg, ecpairPriv);
creata.broadcast(signedTx).then(response => console.log(response));
}) ...
})
Sign transaction by using stdSignMsg and broadcast by using /txs REST API
const signedTx = creata.sign(stdSignMsg, ecpairPriv);
creata.broadcast(signedTx).then(response => console.log(response));
Validate Wallet Address
creata.validateAddress("creata1da4v3fxy3xkkgqr5g60cjmcpvjcjdd5e4m0qwa")
Wallet Address Balance
creata.getAddressBalance("creata1da4v3fxy3xkkgqr5g60cjmcpvjcjdd5e4m0qwa")
Documentation
This library is simple and easy to use. We don't have any formal documentation yet other than examples. Ask for help if our examples aren't enough to guide you