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

Last updated