Provider

Nintondo Wallet API

This documentation is here to help you learn how to create applications for the Nintondo Wallet.

Getting Started

Installation

npm i nintondo-sdk

Usage (manual method)

import { initNintondo } from "nintondo-sdk";

// It will return Nintondo instance if extension is already injected to the website
const nintondo: Nintondo | undefined = initNintondo();

Using React.Context (for React\Next.JS projects)

import { useNintondo, NintondoProvider } from "nintondo-sdk/react";

const Layout = () => {
  return (
    <NintondoProvider>
      <AppEntyPoint />
    </NintondoProvider>
  );
};

const AppEntyPoint = () => {
  const { isConnected, nintondo } = useNintondo();

  return (
    <div>
      {nintondo && <div>Nintondo injected</div>}
      {isConnected && <div>Nintondo connected</div>}
    </div>
  );
};

Methods

connect

nintondo.provider.connect(networkType?: NetworkType) => Promise<string>

To connect to the Nintondo provider.

Parameters Returns
networkType - The network to connect to. Default: bellsMainnet Promise returns stringThe address of the connected account.

Example

await nintondo.connect("bellsMainnet");

> 'tbel1qxdp6v2u0q0tthc67e8sz2t3udykz99yrmnmvc5'

getBalance

nintondo.provider.getBalance() => Promise<number>

The get balance of the connected account.

Parameters Returns
none Promise returns numberThe balance of the connected account.

Example

await nintondo.getBalance();

> 38285545404138

getAccountName

nintondo.provider.getAccountName() => Promise<string>

To get the current account name from the Nintondo provider.

Parameters Returns
none Promise returns stringThe name of the connected account.

Example

await nintondo.getAccountName();

> 'Account 1'

isConnected

nintondo.provider.isConnected() => Promise<boolean>

To get the connection state from the Nintondo provider.

Parameters Returns
none Promise returns booleanThe connection state.

Example

await nintondo.isConnected();

> true

getAccount

nintondo.provider.getAccount() => Promise<string>

To get the current account from the Nintondo provider.

Parameters Returns
none Promise returns stringThe address of the connected account.

Example

await nintondo.getAccount();

> 'tbel1qxdp6v2u0q0tthc67e8sz2t3udykz99yrmnmvc5'

getPublicKey

nintondo.provider.getPublicKey() => Promise<string>

To get the public key of the connected account from the Nintondo provider.

Parameters Returns
none Promise returns stringThe public key of the connected account.

Example

await nintondo.getPublicKey();

> '02e2eac63c70b030f7ed7d1b37a3v56002dcc986e43c35c704532cf913e9dbh098'

getVersion

nintondo.provider.getVersion() => Promise<string>

To get the version of the Nintondo provider.

Parameters Returns
none Promise returns stringThe version of the Nintondo provider in the format x.x.x.

Example

await nintondo.getVersion();

> '0.3.4'

createTx

nintondo.provider.createTx(payload: CreateTxPayload) => Promise<string>

To create a transaction.

Parameters Returns
to: addresss; the address to sendamount: number; the satoshis to sendrecaiverToPayFee: boolean; include fee in the amountfeeRate: number; the network fee rate Promise returns SignedTxHex = stringThe signed transaction hex.

Example

await nintondo.createTx({
    to: "EMpxzi7FujHsQHbrZy7wsuiRHFsvxKZSaB",
    amount: 10_000_000,
    receiverToPayFee: true,
    feeRate: 10
});

> '01000000058661950a3f261f4bbded75684...'

signMessage

nintondo.provider.signMessage(message: string) => Promise<string>

To sign a message.

Parameters Returns
message: string ; The message to sign. Promise returns stringThe signature message.

Example

await nintondo.signMessage("nintondo");

> 'UoQCs9wqDTsyt/3dinivJCO37fuKfqJSVyzNMSS8BrARECNLDf04Od5si0dsJ1RuE8JT/lDWnaJZRcV9WPMkyA=='

calculateFee

nintondo.provider.calculateFee(psbtHex: SignedPsbtBase64, feeRate: number) 
=> Promise<number>

To calculate the fee of a transaction.

Parameters Returns
message: string ; The message to sign. Promise returns numberThe fee of the transaction.

Example

await nintondo.calculateFee("xxxxxxxx", 54)

> 5454

signPsbt

nintondo.providersignPsbt(
    psbtBase64: string,
    options?: SignPsbtOptions) => Promise<string>

To sign a PSBT.

Parameters Returns
psbtBase64 - string: the hex string of psbt to sign- options
  • autoFinalized - boolean: whether finalize psbt after signing, default is true

  • toSignInputs - array:

    • index - number: which input to sign

    • address - string: (at least specify either an address or a publicKey) Which corresponding private key to use for signing

    • publicKey - string: (at least specify either an address or a publicKey) Which corresponding private key to use for signing

    • sighashTypes - number[]: (optionals) sighashTypes

    • disableTweakSigner - boolean :(optionals) Default value is false. Setting it true allows the use of the original private key when signing taproot inputs. | Promise returns SignedPsbtBase64 = stringThe signed PSBT base64 string. |

Example

await nintondo.signPsbt("xxxxxxxx",{toSignInputs:[
{index:0,publicKey:"xxxxxx",disableTweakSigner:true}]})

multiPsbtSign

nintondo.provider.multiPsbtSign(payload: MultiSignPsbtOptions[]) => Promise<string>

To sign multiple PSBT's. This method will traverse all inputs that match the current address to sign.

Parameters Returns
psbtBase64 - string[]: the hex strings of psbt to signoptions - object[]: the options of signing psbt- autoFinalized - boolean: whether finalize psbt after signing, default is true
  • toSignInputs - array:

    • index - number: which input to sign

    • address - string: (at least specify either an address or a publicKey) Which corresponding private key to use for signing

    • publicKey - string: (at least specify either an address or a publicKey) Which corresponding private key to use for signing

    • sighashTypes - number[]: (optionals) sighashTypes

    • useTweakedSigner - boolean :(optionals) . By setting useTweakedSigner, you can forcibly decide whether or not to use tweakedSigner. It has a higher priority than disableTweakSigner. | Promise returns SignedPsbtBase64 = stringThe signed PSBT base64 string. |

Example

await nintondo.multiPsbtSign([
  {
    psbtHex: ["70736274ff01007d...", "70736274ff01007d..."],
    options: [
      {
        autoFinalized: true,
        toSignInputs: [
          {
            index: 0,
            address: "bc1qexampleaddress...",
            sighashTypes: [1, 2],
            useTweakedSigner: false,
          },
        ],
      },
    ],
  },
]);

getNetwork

nintondo.provider.getNetwork() => Promise<string>

To get the currently selected network of the Nintondo wallet.

Parameters Returns
none Promise returns NetworkType = stringThe Network from belcoinjs-lib

Example

await nintondo.getNetwork();

> 'testnet'

disconnect

nintondo.provider.disconnect() => Promise<void>

To disconnect connected account

Parameters Returns
none none

Example

await nintondo.disconnect();  

> undefined

Events

accountsChanged

nintondo.provider.on('accountsChanged', () => void);
nintondo.provider.removeListener('accountsChanged', () => void);
nintondo.provider.removeAllListeners('accountsChanged')

The accountsChanged will be emitted whenever the user's exposed account address changes.


disconnected

nintondo.provider.on('disconnected', () => void);
nintondo.provider.removeListener('disconnected', () => void);
nintondo.provider.removeAllListeners('disconnected')

The disconnected will be emitted whenever the user's network changes.