jackal.nodejs page done
This commit is contained in:
parent
aedd6cf156
commit
bdad075b9e
@ -5,24 +5,22 @@ sidebar_position: 4
|
||||
|
||||
## Quickstart
|
||||
|
||||
To get started using Jackal in the browser, you'll need a few things!
|
||||
### Demo
|
||||
|
||||
A working demo repo can be found [on GitHub](https://github.com/JackalLabs/pup-demo).
|
||||
|
||||
### Pre-requesites
|
||||
|
||||
* [Vue.js](https://vuejs.org/guide/introduction.html) or [React](https://react.dev/learn)
|
||||
* [Jackal.js](https://www.npmjs.com/package/jackal.js)
|
||||
* [Vite](https://vitejs.dev)
|
||||
* Chromium-family browser (Chrome, Brave, Edge, etc)
|
||||
* [Keplr](https://www.keplr.app) or [Leap](https://www.leapwallet.io/cosmos) wallet extension
|
||||
* Nodejs v20+
|
||||
* [Jackal.nodejs](https://www.npmjs.com/package/@jackallabs/jackal.nodejs)
|
||||
* Wallet Mnemonic
|
||||
|
||||
### Setting Up
|
||||
|
||||
To get started, make sure you [start your project using Vite](https://vitejs.dev/guide). If you have an existing React app for example, re-init the project using Vite.
|
||||
|
||||
Install dependencies:
|
||||
```shell
|
||||
npm install jackal.js
|
||||
npm install -D vite-plugin-node-stdlib-browser
|
||||
npm install @jackallabs/jackal.nodejs
|
||||
npm install -D @types/node typescript tscpaths
|
||||
```
|
||||
|
||||
Jackal.js requires Node v20+. The easiest way to manage this is with [NVM](https://github.com/nvm-sh/nvm#installing-and-updating).
|
||||
@ -30,166 +28,28 @@ Jackal.js requires Node v20+. The easiest way to manage this is with [NVM](https
|
||||
nvm use 20
|
||||
```
|
||||
|
||||
#### Updating Vite Config
|
||||
#### Wallet Instantiation
|
||||
|
||||
```js
|
||||
// In vite.config.js:
|
||||
import { defineConfig } from 'vite'
|
||||
import nodePolyfills from 'vite-plugin-node-stdlib-browser'
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
nodePolyfills()
|
||||
],
|
||||
})
|
||||
```
|
||||
|
||||
### Connecting Your Wallet
|
||||
|
||||
Custom chain configurations are required for [Testnet](#testnet-configuration), and for Keplr on [Mainnet](#mainnet-configuration). The following are the correct options to use.
|
||||
Jackal.js additionally supports app-level overrides to the chain default settings. This requires some redundancy, but allows for greater flexibility in projects.
|
||||
|
||||
#### Wallet Selection
|
||||
|
||||
Currently Jackal,js supports Keplr and Leap wallets. Only a single wallet can be used at any time, but you can switch between them as desired.
|
||||
|
||||
```js
|
||||
const selectedWallet = 'keplr'
|
||||
// OR
|
||||
const selectedWallet = 'leap'
|
||||
```
|
||||
|
||||
#### <a name="testnet-configuration"></a>Testnet Configuration
|
||||
|
||||
```js
|
||||
const chainConfig = {
|
||||
chainId: 'lupulella-2',
|
||||
chainName: 'Jackal Testnet II',
|
||||
rpc: 'https://testnet-rpc.jackalprotocol.com',
|
||||
rest: 'https://testnet-api.jackalprotocol.com',
|
||||
bip44: {
|
||||
coinType: 118
|
||||
},
|
||||
coinType: 118,
|
||||
stakeCurrency: {
|
||||
coinDenom: 'JKL',
|
||||
coinMinimalDenom: 'ujkl',
|
||||
coinDecimals: 6
|
||||
},
|
||||
bech32Config: {
|
||||
bech32PrefixAccAddr: 'jkl',
|
||||
bech32PrefixAccPub: 'jklpub',
|
||||
bech32PrefixValAddr: 'jklvaloper',
|
||||
bech32PrefixValPub: 'jklvaloperpub',
|
||||
bech32PrefixConsAddr: 'jklvalcons',
|
||||
bech32PrefixConsPub: 'jklvalconspub'
|
||||
},
|
||||
currencies: [
|
||||
{
|
||||
coinDenom: 'JKL',
|
||||
coinMinimalDenom: 'ujkl',
|
||||
coinDecimals: 6
|
||||
}
|
||||
],
|
||||
feeCurrencies: [
|
||||
{
|
||||
coinDenom: 'JKL',
|
||||
coinMinimalDenom: 'ujkl',
|
||||
coinDecimals: 6,
|
||||
gasPriceStep: {
|
||||
low: 0.002,
|
||||
average: 0.002,
|
||||
high: 0.02
|
||||
}
|
||||
}
|
||||
],
|
||||
features: []
|
||||
}
|
||||
```
|
||||
Jackal.nodejs does not use a traditional wallet like Jackal.js. Instead, `MnemonicWallet.create(mnemonic)` is used for
|
||||
wallet instantiation.
|
||||
|
||||
```js
|
||||
const appConfig = {
|
||||
signerChain: 'lupulella-2',
|
||||
enabledChains: ['lupulella-2'],
|
||||
queryAddr: 'https://testnet-grpc.jackalprotocol.com',
|
||||
txAddr: 'https://testnet-rpc.jackalprotocol.com'
|
||||
}
|
||||
```
|
||||
|
||||
#### <a name="mainnet-configuration"></a>Mainnet Configuration
|
||||
|
||||
```js
|
||||
const chainConfig = {
|
||||
chainId: 'jackal-1',
|
||||
chainName: 'Jackal Mainnet',
|
||||
rpc: 'https://rpc.jackalprotocol.com',
|
||||
rest: 'https://api.jackalprotocol.com',
|
||||
bip44: {
|
||||
coinType: 118
|
||||
},
|
||||
coinType: 118,
|
||||
stakeCurrency: {
|
||||
coinDenom: 'JKL',
|
||||
coinMinimalDenom: 'ujkl',
|
||||
coinDecimals: 6
|
||||
},
|
||||
bech32Config: {
|
||||
bech32PrefixAccAddr: 'jkl',
|
||||
bech32PrefixAccPub: 'jklpub',
|
||||
bech32PrefixValAddr: 'jklvaloper',
|
||||
bech32PrefixValPub: 'jklvaloperpub',
|
||||
bech32PrefixConsAddr: 'jklvalcons',
|
||||
bech32PrefixConsPub: 'jklvalconspub'
|
||||
},
|
||||
currencies: [
|
||||
{
|
||||
coinDenom: 'JKL',
|
||||
coinMinimalDenom: 'ujkl',
|
||||
coinDecimals: 6
|
||||
}
|
||||
],
|
||||
feeCurrencies: [
|
||||
{
|
||||
coinDenom: 'JKL',
|
||||
coinMinimalDenom: 'ujkl',
|
||||
coinDecimals: 6,
|
||||
gasPriceStep: {
|
||||
low: 0.002,
|
||||
average: 0.002,
|
||||
high: 0.02
|
||||
}
|
||||
}
|
||||
],
|
||||
features: []
|
||||
}
|
||||
```
|
||||
|
||||
```js
|
||||
const appConfig = {
|
||||
signerChain: 'jackal-1',
|
||||
enabledChains: ['jackal-1'],
|
||||
queryAddr: 'https://grpc.jackalprotocol.com',
|
||||
txAddr: 'https://rpc.jackalprotocol.com'
|
||||
}
|
||||
```
|
||||
|
||||
#### Bringing the full config together
|
||||
|
||||
```js
|
||||
const finalWalletConfig = {
|
||||
selectedWallet,
|
||||
...appConfig,
|
||||
chainConfig
|
||||
}
|
||||
const m = await MnemonicWallet.create(mnemonic)
|
||||
|
||||
// Hooking up the wallet to your app
|
||||
const wallet = await WalletHandler.trackWallet(finalWalletConfig)
|
||||
const w = await WalletHandler.trackWallet(appConfig, m)
|
||||
```
|
||||
|
||||
Additionally, a query-only mode for the wallet can get accessed via the following:
|
||||
|
||||
```js
|
||||
const wallet = await WalletHandler.trackQueryWallet('https://grpc.jackalprotocol.com') // Use the gRPC-web address of your choice
|
||||
const wallet = await WalletHandler.trackQueryWallet('https://testnet-grpc.jackalprotocol.com') // Use the gRPC-web address of your choice
|
||||
```
|
||||
|
||||
### Buying Storage Space
|
||||
@ -200,9 +60,9 @@ This means giving the protocol $8 USD per month per tb. We can do this with Jack
|
||||
```js
|
||||
const storage = await StorageHandler.trackStorage(wallet)
|
||||
|
||||
// (Wallet address, duration in months (min 1),
|
||||
// (Wallet address)
|
||||
// duration in months (min 1)
|
||||
// space in terabytes (min .001)
|
||||
|
||||
// 2 TB for 1 year:
|
||||
await storage.buyStorage(WALLET_ADDRESS, 12, 2)
|
||||
```
|
||||
@ -210,11 +70,11 @@ await storage.buyStorage(WALLET_ADDRESS, 12, 2)
|
||||
### Creating a Root Folder
|
||||
|
||||
```js
|
||||
const fileIo = await FileIo.trackIo(wallet)
|
||||
const minimumProviderVersion = '1.0.9'
|
||||
const fileIo = await FileIo.trackIo(wallet, minimumProviderVersion)
|
||||
|
||||
const listOfRootFolders = ["Home", ...]
|
||||
// you can create as many root folders as you would like this way. Home is the dashboard default root directory.
|
||||
|
||||
// you can create as many root folders as you would like this way. Home is the Jackal Dashboard default root directory.
|
||||
// The first time a user connects, they must init the system
|
||||
const storage = await StorageHandler.trackStorage(wallet)
|
||||
const msg = storage.makeStorageInitMsg()
|
||||
@ -229,7 +89,7 @@ const newFolderCount = await fileIo.verifyFoldersExist(listOfRootFolders)
|
||||
```js
|
||||
const fileIo = await FileIo.trackIo(wallet)
|
||||
|
||||
const parentFolderPath = PARENT_FOLDER_NAME // for example Dashboard's root folder path is s/Home
|
||||
const parentFolderPath = PARENT_FOLDER_NAME_AND_PATH // for example Dashboard's root folder path is s/Home
|
||||
const parent = await fileIo.downloadFolder(parentFolderPath)
|
||||
|
||||
const listOfChildFolders = ["Movies", "Pictures", ...]
|
||||
@ -242,7 +102,7 @@ await fileIo.createFolders(parent, listOfChildFolders)
|
||||
```js
|
||||
const fileIo = await FileIo.trackIo(wallet)
|
||||
|
||||
const parentFolderPath = PARENT_FOLDER_NAME // for example Dashboard's root folder path is s/Home
|
||||
const parentFolderPath = PARENT_FOLDER_NAME_AND_PATH // for example Dashboard's root folder path is s/Home
|
||||
const parent = await fileIo.downloadFolder(parentFolderPath)
|
||||
|
||||
const file = FILE_OBJECT // this MUST be an instance of File() that is in the browser memory
|
||||
@ -267,7 +127,7 @@ await fileIo.staggeredUploadFiles(uploadList, parent, {counter: 0, complete: 0})
|
||||
const fileIo = await FileIo.trackIo(wallet)
|
||||
|
||||
/* optional */
|
||||
const parentFolderPath = PARENT_FOLDER_NAME // for example Dashboard's root folder path is s/Home
|
||||
const parentFolderPath = PARENT_FOLDER_NAME_AND_PATH // for example Dashboard's root folder path is s/Home
|
||||
const parent = await fileIo.downloadFolder(parentFolderPath)
|
||||
const childrenFiles = parent.getChildFiles()
|
||||
const pathOfFirstChild = parent.getMyChildPath(childrenFiles[0].name)
|
||||
|
Loading…
Reference in New Issue
Block a user