Skip to main content
note

A new version of Mina Docs is coming soon! This page will be rewritten.

Client SDK

The Mina Client Javascript SDK allows generating keypairs, signing and verifying messages, and signing transactions that can be broadcast to the network.

The project contains Typescript and ReasonML typings but can be used from plain NodeJS as well. The following methods are available:

  • genKeys - generates a public/private keypair.
  • derivePublicKey - derives the public key of the corresponding private key.
  • signMessage - signs an arbitrary message.
  • verifyMessage - verifies that a signature matches a message.
  • signPayment - signs a payment using a private key.
  • signStakeDelegation - signs a stake delegation using a private key.
tip

The client SDK enables the ability to generate and sign transactions on an air-gapped device that never exposes a private key to the internet.

Install

yarn add @o1labs/client-sdk
# or with npm:
npm install --save @o1labs/client-sdk

Usage

Typescript

import * as MinaSDK from "@o1labs/client-sdk";

let keys = MinaSDK.genKeys();
let signed = MinaSDK.signMessage("hello", keys);
if (MinaSDK.verifyMessage(signed)) {
console.log("Message was verified successfully")
};

let signedPayment = MinaSDK.signPayment({
to: keys.publicKey,
from: keys.publicKey,
amount: 1,
fee: 1,
nonce: 0
}, keys);

NodeJS

const MinaSDK = require("@o1labs/client-sdk");

let keys = MinaSDK.genKeys();
let signed = MinaSDK.signMessage("hello", keys);
if (MinaSDK.verifyMessage(signed)) {
console.log("Message was verified successfully")
};

let signedPayment = MinaSDK.signPayment({
to: keys.publicKey,
from: keys.publicKey,
amount: 1,
fee: 1,
nonce: 0
}, keys);

ReasonML

  • Install gentype: yarn add -D gentype
  • Install bs-platform: yarn add -D bs-platform
  • Build dependencies: yarn bsb -make-world
module MinaSDK = O1labsClientSdk.CodaSDK;

let keys = MinaSDK.genKeys();
let signed = MinaSDK.signMessage(. "hello", keys);
if (MinaSDK.verifyMessage(. signed)) {
Js.log("Message was verified successfully");
};

let signedPayment = MinaSDK.signPayment({
to_: keys.publicKey,
from: keys.publicKey,
amount: "1",
fee: "1",
nonce: "0"
}, keys);
info

When generating transactions, you must specify the account nonce. This is available for an account by using the CLI using mina advanced get-nonce --address <PUBLIC_KEY> or using GraphQL.