Skip to content

kintsugi-tech/firma-js

 
 

Repository files navigation

firma-js

npm version GitHub tag (latest SemVer) license

The Javascript & TypeScript SDK for FirmaChain

Firma-js is a SDK for writing applications based on javascript & typescript. You can use it client web app or Node.js. This SDK is created inspired by cosmjs and several sdk. All functions of the FirmaChain can be accessed at the service level.

⚠️ We wanted to let you know that the governance module is not accessible at the moment. It requires a patch to become fully operational, which we're actively preparing. We plan to release this patch soon as part of version 0.3.1, at which point the governance module will be enabled. A patch is planned soon to enable the governance module in version 0.3.1.

Features

Most cosmos sdk features are supported

  • Wallet / Bank
  • Nft / Contract
  • Ipfs / Gov
  • Staking / Distribution
  • Feegrant ...and so one

Install

You can install firma-js using NPM

yarn add @firmachain/firma-js

or

npm i @firmachain/firma-js

Usage

Initializing SDK

import { FirmaSDK } from "@firmachain/firma-js"
import { FirmaConfig } from "@firmachain/firma-js"

// use preset config : testnet
const firma = new FirmaSDK(FirmaConfig.TestNetConfig);

// use preset config : mainnet
const firma = new FirmaSDK(FirmaConfig.MainNetConfig);

// or use custom set

let chainConfig = {
   chainID: "colosseum-1",
   rpcAddress: "https://lcd-mainnet.firmachain.dev:26657",
   restApiAddress: "https://lcd-mainnet.firmachain.dev:1317",
   ipfsNodeAddress: "https://ipfs-dev.firmachain.dev",
   ipfsNodePort: 5001,
   ipfsWebApiAddress: "https://ipfs-dev.firmachain.dev",
   hdPath: "m/44'/7777777'/",
   prefix: "firma",
   denom: "ufct",
   defaultFee: 30000,
   defaultGas: 300000,
   isShowLog: false,
}

const firma = new FirmaSDK(chainConfig);

Create wallet account

// create new wallet
const newWallet = await firma.Wallet.newWallet();

// generateMnemonic
const mnemonic = await firma.Wallet.generateMnemonic();
const index = 0;

// or from mnemonic
const wallet = await firma.Wallet.fromMnemonic(mnemonic, index);
console.log(await wallet.getAddress());

Import account by private key

const privateKey = wallet.getPrivateKey();
const wallet1 = await firma.Wallet.fromPrivateKey(privateKey);

Get chaion status (include height, time etc)

const result = await firma.Chain.getChainStatus();
console.log(result);

Get FIRMA balance of specific account

const address = await wallet.getAddress();
const balance = await firma.Bank.getBalance(address);
console.log("balance: " + balance);

Get transaction by hash

const txHash = "0xC5509A32CF57798F8C3185DFAF03BD2D09DFC04FE842283ECA9298F5F60E340F";
const result = await firma.Chain.getTransactionByHash(txHash);
console.log(result);

Bank send - create tx and broadcast

const fctAmount = 10;
let result = await firma.Bank.send(wallet, address, fctAmount);

Bank send - extended version

const fctAmount = 10;
let result = await firma.Bank.send(wallet, address, fctAmount, { memo: "", fee: 30000, gas: 300000 });

Calculate gas

let gas = await firma.Bank.getGasEstimationSend(wallet, address, fctAmount);

Mint NFT

const tokenURI = "https://ipfs-firma-devnet.firmachain.org/ipfs/QmYsezxzunake9EmyoU4HsWKEyHQLgE3syTEpTSQEhNChA";
let result = await firma.Nft.mint(wallet, tokenURI);

Transfer NFT

const tokenId = 1;
let result = await firma.Nft.transfer(wallet, address, tokenId);

Burn NFT

const tokenId = 1;
let result = await firma.Nft.burn(wallet, tokenId);

You can see everything usage of firma-js on the test folder.
https://github.com/FirmaChain/firma-js/tree/main/test

About

Javascript & TypeScript SDK for FirmaChain

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 100.0%