@scintilla-network/js-sdk v1.3.0
js-sdk
JS SDK to build with Scintilla. Include a Client to the network.
Install
ES5/ES6 via NPM
In order to use this library, you will need to add it to your project as a dependency.
Having NodeJS installed:
npm install @scintilla-network/js-sdk
CDN Standalone
For browser usage, you can also directly rely on unpkg :
<script src="https://unpkg.com/@scintilla-network/js-sdk"></script>
Some considerations
We define a Wallet as a primitives that is initiated from a root private key
A Wallet can be derived into multiple Account (that have individual public/private key pair).
Client
import { Client, Mnemonic } from '@scintilla-network/js-sdk'
const client = new Client();
const mnemonic = new Mnemonic();
// Initiate a wallet from a specific mnemonic or private key
const wallet = client.createWallet(mnemonic);
// Each wallet allow to generate multiple account, by default, it will be index 0.
const account = wallet.getAccount();
// Get an account's Address on jmesxxxx format.
const address = account.getAddress();
const balance = await account.fetchBalance();
// Send transaction
const txResponse = await account.sendMessage({
type: 'transfer',
opts: {
recipientAddress: "sct1g2vaept3rxjvfzyfmem5am5x74n4qygq58jy9v",
recipientAmount: 172064,
}
})
Usage on React-Native
While this library will handle secpk1256 generation, upon creating a new Mnemonic, it might causes some issues despite overwritting crypto
module.
If so, you can pass specific bytes to the Mnemonic function.
import 'react-native-get-random-values'
const randomBytes = crypto.getRandomValues(new Uint8Array(32));
const mnemonic = Mnemonic.generateMnemonic(randomBytes);
API
Client
createWallet
Passing either a Mnemonic or a private key, it will generate a Wallet object.
const mnemonic = new Mnemonic();
const client = new Client();
const wallet = client.createWallet(mnemonic);
getSupply
Allow an optional denom parameter (default: usct). Pass bujmes to get the voting rights supply.
const supply = await client.bank.getSupply();
getValidatorInfo
Return a specific validator information.
const validatorInfo = await client.validator.getValidatorInfo(validatorAddress);
getValidators
Return the list of validators.
const validators = await client.validator.getValidators();
Wallet
getAccount
Return an Account object from an optional specified index.
const account = wallet.getAccount();
Account
getAddress
Return the account address on jmesxxxx format. Allow an optional address index parameter (default: 0).
const address = account.getAddress();
async fetchBalance
Return the account balance.
Allow an optional address parameter (default .getAddress()).
const balance = await account.fetchBalance();
getVotingRights
Return the account voting rights. Allow an optional address parameter (default .getAddress()).
const votingRights = account.getVotingRights();
sendMessage
Send a message (transfer) from the account.
const txResponse = await account.sendMessage({
type: 'transfer',
opts: {
recipientAddress: "sct1g2vaept3rxjvfzyfmem5am5x74n4qygq58jy9v",
recipientAmount: 172064,
}
})
delegateTokens
Delegate tokens to a validator. Specified amount is in Coin primitives.
const txResponse = await account.delegateTokens(validatorAddress, amount);
undelegateTokens
Undelegate tokens from a validator. Specified amount is in Coin primitives.
const txResponse = await account.unDelegateTokens(validatorAddress, amount);
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago