English | 简体中文
✨ Characteristics
- GotaBit.js was created to help new developers get started with their first dApps. It is just a wrapper package to easily import needed features from CosmJS.
- GotaBit.js is not only a wrapper around CosmJS, but also brings some preconfigured functions to simplify the setup of SigningClient.
- GotaBit.js provides properties and methods such as the GotaBit constructor to make it easier to handle transactions and other operations.
⚡ Get started
1. Install
Package Manager using
$ npm install gotabit
$ yarn add gotabit
$ pnpm add gotabit
in the browser
<script crossorigin src="https://unpkg.com/gotabit@latest/dist/bundle.js"></script>
<script crossorigin src="https://res.gotabit.io/jssdk/dist/bundle.js"></script>
2. Use
Initialize SDK
Calling the SDK initialization method, the first parameter supports two types
string, There are currently three environments: "local" | "test" | "main".
object, Please check GotaBitConfig type for details, custom configurations are supported.
import { GotaBit } from "gotabit";
const gotabit = await GotaBit.init('test', 12);
console.log(gotabit);
console.log(gotabit.wallet);
const [{ address }] = await gotabit.wallet.getAccounts();
console.log(address);
Generate Wallet Instructions
- number:
The number of words in the mnemonic (12, 15, 18, 21, 24).
import { GotaBit } from "gotabit";
const gotabit = await GotaBit.init('test', 12);
console.log(gotabit);
import { GotaBit } from "gotabit";
const mnemonic =
"dinner proud piano mention silk plunge forest fold trial duck electric define";
const gotabit = await GotaBit.init('test', mnemonic);
console.log(gotabit)
- object:
type("password" | "keplr" | "ledger").
-
password
import { GotaBit } from "gotabit";
const pwd = {
type: 'password',
key: '123456',
data: '{"type":"directsecp256k1hdwallet-v1","kdf":{"algorithm":"argon2id","params":{"outputLength":32,"opsLimit":24,"memLimitKib":12288}},"encryption":{"algorithm":"xchacha20poly1305-ietf"},"data":"t6K8D6b7ZHG4jD6c2OFfahvO6Tl640LUjxlyx9UIPUnbQnygYPW1KtsWjJzYGmtz1OXiM7pN0VedXk9Q/MwnurQLRcm3Smen5lftD4Wf0pNsJCZ5q3IsyhjWYoYH5sOwuFnnxLCxVJgjHuqKEPHlnqxyCrgOOr5VRyHtsCG2KqNtw+K9HWyVdjrNgMCkRD09xqJWQHejtFgqHXSl0Tfnf05ycu1DPaxkdjD2AYobjgxPDHhLP0lGGS6yj5IN10g="}',
};
const gotabit = await GotaBit.init('test', pwd);
console.log(gotabit.wallet);
const [{ address }] = await gotabit.wallet.getAccounts();
console.log(address);
-
keplr
import { GotaBit } from "gotabit";
const gotabit = await GotaBit.init('test', { type: "keplr" });
-
ledger
import { GotaBit } from "gotabit";
const gotabit = await GotaBit.init('test', { type: "ledger" });
Check Account Balance
import { GotaBit } from "gotabit";
const address = 'gio1tseh0grt8j8klrdunpudflvy9lfn3rl50zdpu8';
const gotabit = await GotaBit.init('test');
const client = await gotabit.client();
const balance = await client.getAllBalances(address);
console.log('balance:', balance);
Client
- Get a read-only cosmwasm client
import { GotaBit } from "gotabit";
const mnemonic =
"dinner proud piano mention silk plunge forest fold trial duck electric define";
const gotabit = await GotaBit.init('test', mnemonic);
const client = await gotabit.client(false, true);
console.log(client);
Interacting with contracts
const { GotaBit } = GotaBitJS;
const mnemonic =
"dinner proud piano mention silk plunge forest fold trial duck electric define";
const cw20_token_address =
"gio14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sl0hu5t";
const gotabit = await GotaBit.init('test', mnemonic);
const [from_wallet] = await gotabit.wallet.getAccounts();
const client = await gotabit.wasmClient(true);
const config = await client.queryContractSmart(cw20_token_address, {
balance: {
address: from_wallet.address
}
});
console.log(config)
SafeBot Encrypt & decrypt
import { Buffer, fromUtf8, GotaBit, SafeBotEcies, SafeBotChaCha20, SafeBotXChaCha20, safeBotSha1, safeBotSha256, toUtf8 } from "gotabit";
const text = toUtf8('This a plain text.');
const sha256Digest = safeBotSha256(text);
console.log('sha256-digest:', sha256Digest);
const sha1Digest = safeBotSha1(text);
console.log('sha1-digest:', sha1Digest);
let encrypted = await SafeBotXChaCha20.encrypt(text, '123456');
let plaintext = await SafeBotXChaCha20.decrypt(encrypted, '123456');
console.log('SafeBotXChaCha20-encrypted:', Buffer.from(encrypted).toString('base64'));
console.log('SafeBotXChaCha20-plaintext:', fromUtf8(plaintext));
let safeBotEncrypted = await SafeBotChaCha20.encrypt(text, '123456');
let safeBotPlaintext = await SafeBotChaCha20.decrypt(safeBotEncrypted, '123456');
console.log('SafeBotChaCha20-encrypted:', Buffer.from(safeBotEncrypted).toString('base64'));
console.log('SafeBotChaCha20-plaintext:', fromUtf8(safeBotPlaintext));
const gotabit = await GotaBit.init('test', 12, {
prefix: "gid",
hdPaths: 'm/199'
});
const [{ address, pubkey, privkey }] = await gotabit.wallet.getAccountsWithPrivkeys();
console.log("address: ", address);
console.log("mnemonic: ", gotabit.wallet.mnemonic);
console.log("pubkey: ", Buffer.from(pubkey).toString("hex"));
console.log("privkey: ", Buffer.from(privkey).toString("hex"));
encrypted = await SafeBotEcies.encrypt(text, pubkey);
plaintext = await SafeBotEcies.decrypt(encrypted, privkey);
console.log('ecies-encrypted:', encrypted.toString('base64'));
console.log('ecies-plaintext:', fromUtf8(plaintext));
🔍 Documentation
GotaBit Docs.
🎈 License
This is a fork from CosmWasmJS
This software is licensed under the Apache 2.0 license.
© 2022 GotaBit Limited