Skip to content

Wallet Interface

Make your zkApp compatible with Mina wallets.

To make your zkApp compatible with Mina wallets, we've created a strongly typed interface for window.mina and injected providers found by Provider Discovery.

Queries

mina_accounts

Get accounts. If not authorized, the response is an empty array.

import { createStore } from '@mina-js/connect'
 
const store = createStore()
const { provider } = store.getProviders()[0]
const { result } = await provider.request<'mina_accounts'>({ method: 'mina_accounts' })

mina_requestAccounts

Acts like mina_accounts but with a prompt to authorize in case user didn't authorize yet.

import { createStore } from '@mina-js/connect'
 
const store = createStore()
const { provider } = store.getProviders()[0]
const { result } = await provider.request<'mina_requestAccounts'>({ method: 'mina_requestAccounts' })

mina_networkId

Get the network ID. It's a string that represents the current network. Values are mina:mainnet or mina:testnet.

import { createStore } from '@mina-js/connect'
 
const store = createStore()
const { provider } = store.getProviders()[0]
const { result } = await provider.request<'mina_networkId'>({ method: 'mina_networkId' })

mina_getBalance

Get the balance of the current account. The value is already parsed to Mina units.

import { createStore } from '@mina-js/connect'
 
const store = createStore()
const { provider } = store.getProviders()[0]
const { result } = await provider.request<'mina_getBalance'>({ method: 'mina_getBalance' })

mina_requestNetwork

Get network information. Similar to mina_networkId, but more detailed. It returns current network's RPC url, name, and slug (network ID).

import { createStore } from '@mina-js/connect'
 
const store = createStore()
const { provider } = store.getProviders()[0]
const { result } = await provider.request<'mina_requestNetwork'>({ method: 'mina_requestNetwork' })

mina_getState

Returns filtered Public Credentials.

import { createStore } from '@mina-js/connect'
 
const store = createStore()
const { provider } = store.getProviders()[0]
const { result } = await provider.request<'mina_getState'>({
  method: 'mina_getState',
  params: [{ issuer: "University of Example" }, []],
})

Commands

mina_sign

import { createStore } from '@mina-js/connect'
 
const store = createStore()
const { provider } = store.getProviders()[0]
const { result } = await provider.request<'mina_sign'>({ method: 'mina_sign', params: ['My message'] })

mina_signTransaction

Sign payment or delegation:

import { createStore } from '@mina-js/connect'
 
const store = createStore()
const { provider } = store.getProviders()[0]
const { result } = await provider.request<'mina_signTransaction'>({
  method: 'mina_signTransaction',
  params: [{
    transaction: {
      // You should probably get the right nonce from Klesia for that.
    	nonce: '1',
    	from: "B62qmWKtvNQTtUqo1LxfEEDLyWMg59cp6U7c4uDC7aqgaCEijSc3Hx5",
    	to: "B62qmWKtvNQTtUqo1LxfEEDLyWMg59cp6U7c4uDC7aqgaCEijSc3Hx5",
    	amount: '3000000000',
    	fee: '100000000',
    }
  }]
})

Sign zkApp command:

import { createStore } from '@mina-js/connect'
 
const store = createStore()
const { provider } = store.getProviders()[0]
const { result } = await provider.request<'mina_signTransaction'>({
  method: 'mina_signTransaction',
  params: [{
    command: {
      zkappCommand: {},
      feePayer: {
        feePayer: 'B62qmWKtvNQTtUqo1LxfEEDLyWMg59cp6U7c4uDC7aqgaCEijSc3Hx5',
        fee: '100000000',
        nonce: '1',
        memo: 'Hello, Mina!',
      }
    }
  }]
})

mina_signFields

import { createStore } from '@mina-js/connect'
 
const store = createStore()
const { provider } = store.getProviders()[0]
const { result } = await provider.request<'mina_signFields'>({
  method: 'mina_signFields',
  params: [['1', '2', '3']]
})

mina_createNullifier

import { createStore } from '@mina-js/connect'
 
const store = createStore()
const { provider } = store.getProviders()[0]
const { result } = await provider.request<'mina_createNullifier'>({
  method: 'mina_createNullifier',
  params: [['1', '2', '3']]
})

mina_sendTransaction

Send a signed transaction to the network.

import { createStore } from '@mina-js/connect'
 
const store = createStore()
const { provider } = store.getProviders()[0]
const { result } = await provider.request<'mina_sendTransaction'>({
  method: 'mina_sendTransaction',
  params: [{ input: {}, signature: { field: 'xyz', scalar: 'xyz' } }, 'payment']
})

mina_setState

Saves a new Public Credential.

import { createStore } from '@mina-js/connect'
 
const store = createStore()
const { provider } = store.getProviders()[0]
const { result } = await provider.request<'mina_setState'>({
  method: "mina_setState",
  params: [
    {
      objectName: "Pallad Mock Credential",
      object: {}, // DID Credential with a Kimchi proof
    },
  ],
})

mina_switchChain

Prompts user to switch to another network. It's useful for dApps that support multiple networks.

import { createStore } from '@mina-js/connect'
 
const store = createStore()
const { provider } = store.getProviders()[0]
await provider.request<'mina_switchChain'>({
  method: 'mina_switchChain',
  params: ['mina:mainnet']
})

mina_addChain

Prompts user to add a new chain.

import { createStore } from '@mina-js/connect'
 
const store = createStore()
const { provider } = store.getProviders()[0]
await provider.request<'mina_addChain'>({
  method: 'mina_addChain',
  params: [
    {
      name: 'Mina Fakenet',
      slug: 'mina:fakenet',
      url: 'https://fakenet.example.com',
    }
  ]
})