Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

navi-sdk

Package Overview
Dependencies
Maintainers
1
Versions
62
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

navi-sdk

The NaviSDK Client provides a set of tools for interacting with sui blockchain networks, specifically designed for handling transactions, accounts, and smart contracts in a streamlined and efficient manner. This documentation covers the setup, account man

  • 1.0.8
  • npm
  • Socket score

Version published
Weekly downloads
869
decreased by-20.06%
Maintainers
1
Weekly downloads
 
Created
Source

NaviSDK Client Documentation

Introduction

The NaviSDK Client provides a set of tools for interacting with sui blockchain networks, specifically designed for handling transactions, accounts, and smart contracts in a streamlined and efficient manner. This documentation covers the setup, account management, and transaction handling within the NaviSDK ecosystem.

Getting Started

Installation

Before you can use the NaviSDK Client, you need to set up your project environment.

npm i navi-sdk

Creating and Managing Accounts

Creating a Default Account

To create a default account, you will need a mnemonic phrase or we will generate a new one for you. We will never save user's mnemonic phrase

const mnemonic = ''; // Use an existing mnemonic or leave empty to generate a new one
const client = new naviSDKClient({mnemonic, networkType: "mainnet", wordLength: 12}); //WordLength supports 12 or 24 words

Create/Delete a new Account

client.createNewAccount();
console.log(`index 1:`, client.getMnemonic(accountIndexNumber)); //You may print it out to check the mnemonic
client.deleteAccount(index = 0);

Use a specific 12|24 word Mnemonic

client.createNewAccount({mnemonic: 'potato potato potato potato potato potato potato potato potato potato potato potato'});
// Double check the index 2 account
console.log(`index 2:`, client.getMnemonic(2));

Return All Accounts under the Client

client.getAllAccounts()
client.getAllMnemonic()
//Return Sample
index:0, address: 0xa814b8c01b111f5e440e5d4785925a033961915c2f44d22ca71619ac73534ee7
index:1, address: 0xd8be370139dd297924e31f6a507ba3a1d5f52f98f04f144bb75100d179698f84
index:2, address: 0xca29dbf32047fba966fa5aca7e378ba11171b3817f53ad324489a138288cc02d

Create Account Cap

client.createAccountCap(index = 0) //Index 0 Account will create an Account Cap

Get Specific Account Address

client.getPublicKey(index = 0)
client.getMnemonic(index = 0)

Get Objs and Token Info

client.getAllObjs(index = 0) //Return all Objects that account has

//Get all objs for this type of token
client.getTokenObjs(index = 0, coinType = "0x2::sui::SUI")
//Or you may import token address from address
import {AddressMap} from 'navi-sdk/dist/address'
client.getTokenObjs(index = 0, coinType = AddressMap['Sui'])

Send Token or Objects

client.sendToken(index = 0, coinType = "0x2::sui::SUI", your_recipient_address, amount)
client.sendTokenToMany(index = 0, coinType = "0x2::sui::SUI", [addr1, addr2, .. addrN], [amount1, amount2, .. amountN])

client.transferObj(index = 0, obj = "0xaaaaa", your_recipient_address)
client.transferObjToMany(index = 0, [obj1, obj2, ...], [addr1, addr2, ...])

Navi Interaction

Supply/Withdraw/Borrow/Repay

You may Simply input 'NAVX' or 'full-token-address' Current These Token support simple string as input:

Sui | NAVX | vSui | USDC | USDT | WETH | CETUS | HASui

client.deposit(index = 0, coinType = "0x2::sui::SUI"|'Sui', amount)
client.depositWithAccountCap(index = 0, coinType = "0x2::sui::SUI"|'Sui', amount, accountCap_Address_that_you_own)


client.withdraw(index = 0, coinType = "NAVX", amount)
client.withdrawWithAccountCap(index = 0, coinType = "NAVX", amount, accountCap_Address_that_you_own)

client.borrow(index = 0, coinType = "NAVX", amount)
client.repay(index = 0, coinType = "NAVX", amount)

Customized PTB

Navi Flash Loan Sample


import { naviSDK } from 'navi-sdk'
import { TransactionBlock } from "@mysten/sui.js/transactions";
import {depositToken, borrowToken, flashloan,repayFlashLoan, SignAndSubmitTXB, mergeTokens} from 'navi-sdk/dist/libs/PTB'
import { Pool, PoolConfig } from "navi-sdk/dist/types";
import { pool } from 'navi-sdk/dist/address'

const mnemonic = "";
const client = new naviSDK({mnemonic: mnemonic, networkType: "mainnet", wordLength: 12});

// Initialize the TransactionBlock
let txb = new TransactionBlock();
let sender = client.getPublicKey(0);
txb.setSender(sender);

// Example operation: deposit Sui to NAVI protocol
const poolName = 'Sui'; // Supported: Sui/NAVX/vSui/USDC/USDT/WETH/CETUS/HAsui
const amount_to_deposit = 100000000; //Deposit 0.1 Sui
const amount_to_borrow = 10000000; //Borrow 0.01 Sui

const Sui_Pool: PoolConfig = pool[poolName as keyof Pool];
const [coins] = txb.splitCoins(txb.gas, [amount_to_deposit]);
const [balance, receipt] = flashloan(txb, Sui_Pool, 1 * 1e9); // Flashloan 1 Sui

// Transfer Loan and receipt to sender
txb.transferObjects([balance], sender);
depositToken(txb, Sui_Pool, coins, amount_to_deposit);
borrowToken(txb, Sui_Pool, amount_to_borrow);

repayFlashLoan(txb, Sui_Pool, receipt, 1200000000); // Repay with Sui

const result = SignAndSubmitTXB(txb, client.client(0), client.keypair(0));
console.log("result: ", result);


FAQs

Package last updated on 08 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc