Skip to content

Getting Started

Start with MinaJS Accounts.

MinaJS Accounts shares an API similar to Viem.

Installation

$ npm install @mina-js/accounts

Nightly builds

$ npm install https://pkg.pr.new/palladians/mina-js/@mina-js/accounts@main

Utilities

generateMnemonic

import { generateMnemonic, english } from '@mina-js/accounts'
 
const mnemonic = generateMnemonic({ wordlist: english });

generatePrivateKey

import { generatePrivateKey } from '@mina-js/accounts'
 
const privateKey = generatePrivateKey();

mnemonicToAccount

import { mnemonicToAccount } from '@mina-js/accounts'
 
const account = mnemonicToAccount({ mnemonic: 'your mnemonic here' });

privateKeyToAccount

import { privateKeyToAccount } from '@mina-js/accounts'
 
// Mainnet account
const mainnetAccount = privateKeyToAccount({ privateKey: 'your private key here' });
// Testnet account
const testnetAccount = privateKeyToAccount({
  privateKey: 'your private key here',
  network: 'testnet'
});

hdKeyToAccount

import { hdKeyToAccount, hex, HDKey } from '@mina-js/accounts'
 
const hdKey = HDKey.fromMasterSeed(hex.decode("59eabf9e9..."));
 
const addressIndexAccount = hdKeyToAccount({ hdKey, addressIndex: 5 });
const accountIndexAccount = hdKeyToAccount({ hdKey, accountIndex: 5 });
const customPathAccount = hdKeyToAccount({ hdKey, path: "m/44'/12586'/0'/0/5" });

hex

Exported from @scure/base.

HDKey

Exported from @scure/bip32.

Account operations

Sign a message

import { mnemonicToAccount } from '@mina-js/accounts'
 
const account = mnemonicToAccount({ mnemonic: 'your mnemonic here' });
 
const signedMessage = await account.signMessage({ message: 'your message here' });

Sign a transaction

import { mnemonicToAccount } from '@mina-js/accounts'
 
const account = mnemonicToAccount({ mnemonic: 'your mnemonic here' });
 
const signedTransaction = await account.signTransaction({
  transaction: {
  	nonce: 1n,
  	from: "B62qmWKtvNQTtUqo1LxfEEDLyWMg59cp6U7c4uDC7aqgaCEijSc3Hx5",
  	to: "B62qmWKtvNQTtUqo1LxfEEDLyWMg59cp6U7c4uDC7aqgaCEijSc3Hx5",
  	amount: 3000000000n,
  	fee: 100000000n,
  }
});

Sign fields

import { mnemonicToAccount } from '@mina-js/accounts'
 
const account = mnemonicToAccount({ mnemonic: 'your mnemonic here' });
 
const signedFields = await account.signFields({ fields: [1n, 2n, 3n] });

Create a nullifier

import { mnemonicToAccount } from '@mina-js/accounts'
 
const account = mnemonicToAccount({ mnemonic: 'your mnemonic here' });
 
const nullifier = await account.createNullifier({ message: [1n, 2n, 3n] });