Skip to content

ProtoconNet/mitumjs

Repository files navigation

Abstraction

  • mitumjs is the official JavaScript/TypeScript SDK for the Mitum blockchain.
  • The Mitum blockchain operates on a multi-sig account basis. However, for user convenience, single-sig is prioritized.
  • Method names are designed to be called intuitively from the user's perspective and use camelCase notation for consistency.

1. Install (Recommended)

For all dApp and back-end development, we strongly recommend using the official npm package.

This package automatically provides the correct bundle for your environment (Node.js or Browser).

$ npm install @mitumjs/mitumjs

2. Usage

The SDK provides two main classes, which are both available as named exports:

Mitum: The main SDK class for core logic. Use this to create operations, generate keys, and communicate directly with a Mitum node (via its API Endpoint).

BrowserProvider: The EIP-1193 standard provider. Use this in dApps to connect to browser wallets like Fact Wallet (window.imfact) for account requests and transaction signing.


A. For Browser Environments (dApps, Vite, React)

Use the ES Module (ESM) bundle via import. This bundle includes necessary browser polyfills (like Buffer) automatically. You no longer need to configure polyfills in your vite.config.ts or perform manual fixes

// Example: Connecting to Fact Wallet in a React dApp
import { Mitum, BrowserProvider } from '@mitumjs/mitumjs';

// 1. Initialize the Provider by wrapping the wallet's injected object
const provider = new BrowserProvider(window.imfact);

// 2. Request account access (triggers wallet popup)
const accounts = await provider.requestAccounts();
const userAddress = accounts[0];

// 3. Initialize the Mitum core class to create operations
//    This requires the Node's API Endpoint for blockchain queries/submissions.
const mitum = new Mitum("https://testnet.imfact.im"); // API endpoint for imFact Testnet

const recipientAddress = "0x...";
const op = mitum.currency.transfer(userAddress, recipientAddress, "FACT", 100);
const txObject = op.toHintedObject(); // Create the JSON object for the wallet

// 4. Send the transaction object to the wallet for signing
const factHash = await provider.sendTransaction(txObject);
console.log('Transaction Fact Hash:', factHash);

// 5. Listen for wallet events
provider.on('accountsChanged', (newAccounts) => {
  console.log('Wallet accounts changed:', newAccounts);
});

B. For Node.js Environments (Back-end, Scripts)

Use the CommonJS (CJS) bundle via require. This bundle uses Node.js native modules (like the built-in Buffer) for optimal performance.

// Example: Sending a transaction from a Node.js server
const { Mitum } = require('@mitumjs/mitumjs');

// 1. Initialize the Mitum core class with the Node's API Endpoint URL
//    This requires the Node's API Endpoint for blockchain queries/submissions.
const mitum = new Mitum("https://testnet.imfact.im"); // API endpoint for imFact Testnet

// 2. Create and sign an operation
const sender = "0x...";
const privateKey = "...";
const recipientAddress = "0x...";
const op = mitum.currency.transfer(sender, recipientAddress, "FACT", 100);
op.sign(privateKey);

// 3. Send the signed operation directly to the node's API Endpoint
const sendOperation = async () => {
  try {
    const info = await mitum.operation.send(op);
    console.log(info); // Check the operation sended sucessfully.
    const receipt = await info.wait(); // Wait for the transaction to be confirmed
    console.log(receipt);
  } catch (error) {
    console.error("Failed to send operation:", error);
  }
};

sendOperation();

3. Important Functions Note

The operation objects created by the Mitum SDK (e.g., mitum.currency.transfer(...)) are raw transaction messages.

  • They require signing via the .sign() method (in Node.js) or a provider.sendTransaction(-) request (in browsers).

  • A signed operation must be sent to the network via the mitum.operation.send() function (in Node.js) or provider.sendTransaction() (in browsers) to be executed.


4. Mitum JS SDK User Guide

For detailed information on all functions, models, and advanced usage, please refer to our official GitBook documentation.

Be sure to check it out before using the SDK.

📖 Mitum JS SDK user guide


5. Exports Overview

Classes

  • Mitum — Main SDK class for core logic and node communication.
  • BrowserProvider — EIP-1193 Provider for browser wallet (dApp) communication.

Types

  • Fact, BaseOperation, Item, Authentication, ProxyPayer, Settlement
  • Account, HDAccount, defaultPath

Utilities

  • isOpFact(object)
  • isHintedObject(object)
  • isHintedObjectFromUserOp(object)


Building from Source (For Contributors)

If you need to contribute to the SDK development, you can build it locally.

$git clone [https://github.com/ProtoconNet/mitumjs.git$](https://github.com/ProtoconNet/mitumjs.git$) cd mitumjs
$ npm install
$ npm run build

After building, the dist directory will contain bundle.cjs.cjs (for Node.js testing) and bundle.esm.mjs (for browser testing).

About

framework for mitum2 network

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •