Ninji Wallet
  • 🥷Ninji Wallet for Injective
  • PRODUCT / FEATURE
    • Extension
    • Mobile App
  • USER GUIDE
    • Basic
      • Mobile App
        • How to download and install Ninji wallet?
        • How to set up Ninji Wallet
        • How to add a new Hot wallet
        • How to manage wallets
        • How to manage tokens
        • How to add a custom token
        • How to send or receive tokens
        • How to send or receive NFTs
        • How to use DApp Browser
        • How to buy cryptocurrency by fiat on Ninji Wallet
        • How to turn on Biometric and change Passcode
        • General Settings
      • Extension
        • How to install Ninji Wallet Extension
        • How to set up Ninji Extension Wallet
        • How to add a new Hot wallet
        • How to manage wallets
        • How to manage tokens
        • How to add a custom token
        • How to send or receive tokens
        • How to send token with SpaceID
        • How to send or receive NFTs
        • How to use Staking feature
          • How to stake on Ninji Wallet
          • How to unstake on Ninji Wallet
          • How to claim Reward
        • How to override wallet
        • General settings
    • FAQs
      • Balances Not Showing on My Wallet
      • I can't recover my wallet by using Seed Phrase
      • What is the difference between Private Key and Seed Phrase?
      • Are there any service fees on Ninji Wallet when I send tokens?
      • Can I change the wallet name?
      • How do I contact Ninji Wallet for support?
  • INTEGRATE NINJI WALLET
    • Dev Guide - Injective DApps Integration
    • Cosmos Kit
    • Injective Kit
    • Shuttle Kit
    • Coinhall Kit
  • Legal
    • Terms of Service
    • Privacy Policy
  • OFFICIAL LINKS
    • Website
    • Twitter
    • Discord
  • Brand Assets
    • Brand Assets
    • Redirection link
Powered by GitBook
On this page
  • To detect Ninji Wallet Extension
  • To connect Ninji Wallet Extension
  • To disconnect Ninji Wallet Extension
  • API Reference
  • List of events
  1. INTEGRATE NINJI WALLET

Dev Guide - Injective DApps Integration

Welcome to Ninji Wallet Developer Guide. This documentation contains guides for developers to get started developing on Ninji Wallet.‌

To detect Ninji Wallet Extension

To detect whether your browser is running Ninji Wallet Extension, please use:

if(window.ninji ){
    console.log('Ninji Extension is installed!');
}

To connect Ninji Wallet Extension

Enable Connection

window.ninji.enable(chainId: string)
// Only support Injective main network

The window.ninji.enable(chainIds) method requests the extension to be unlocked if it's currently locked. If the user hasn't given permission to the webpage, it will ask the user to give permission for the webpage to access Ninji.

If the user cancels the unlock or rejects the permission, an error will be thrown.

Note: When users have multiple wallets in the extension, users have the option to choose which wallet they want to activate.

To disconnect Ninji Wallet Extension

To disconnect Ninji Extension, please use:

window.ninji.disconnect()

API Reference

Get Address / Public Key

window.ninji.getKey(chainId: string): Promise<Key>

If the webpage has permission and Ninji is unlocked, this function will return the address and public key in the following format:

{
 // Name of the selected key store.
 name: string;
 algo: string;
 pubKey: Uint8Array;
 address: Uint8Array;
 bech32Address: string;
 isNanoLedger: boolean;
}

Sign Amino

signAmino(chainId: string, signer: string, signDoc: StdSignDoc, signOptions?: SignOptions): Promise<AminoSignResponse>

Similar to CosmJS OfflineSigner's signAmino, but Ninji's signAmino takes the chain-id as a required parameter. Signs Amino-encoded StdSignDoc.

Sign Direct / Protobuf

interface SignDoc {
  bodyBytes?: Uint8Array | null;
  authInfoBytes?: Uint8Array | null;
  chainId?: string | null;
  accountNumber?: Long | null;
}

signDirect(chainId:string, signer:string, signDoc: SignDoc, signOptions?: SignOptions): Promise<DirectSignResponse>

Similar to CosmJS OfflineDirectSigner's signDirect, but Ninji's signDirect takes the chain-id as a required parameter. Signs Proto-encoded StdSignDoc.

Delegate Transaction broadcasting:

Webpages can use this function to delegate the broadcasting of the transaction to LCD endpoints configured in the ninji wallet. If the broadcast is successful, this method will return the transaction hash. Otherwise, it will throw an error.

sendTx(
 chainId: string,
 tx: Uint8Array,
 mode: BroadcastMode
): Promise<Uint8Array>;

CosmJS example

Ninji’s API is similar to Keplr's to keep the integration of Ninji for the dApp as easy as possible.

import { GasPrice, SigningStargateClient } from '@cosmjs/stargate'
await window.ninji.enable(chainId);

const offlineSigner = window.ninji.getOfflineSigner(chainId, signOptions);
const accounts = await offlineSigner.getAccounts();
const rpcUrl = "" // Replace with a RPC URL for the given chainId
const signingStargateClient = await SigningStargateClient.connectWithSigner(
  rptycUrl,
  offlineSigner,
  {
    gasPrice: GasPrice.fromString("500000000inj"),
  }
)

List of events

Currently we only support some action event from wallet extension

window.ninji.on('event_name', callback);

​//Example
window.ninji.on('close', () => window.location.reload());
window.ninji.on('accountsChanged', () => window.location.reload());
Events
Trigger

accountsChanged

Receive when active account changed in Extension

networkChanged

Receive when active network changed in Extension

Method
Description

on(event, callback)

Add event listener

off(event, callback)

Remove event listener

PreviousHow do I contact Ninji Wallet for support?NextCosmos Kit

Last updated 1 year ago