-
mitum.js is the framework of the mitum blockchain written in the typescript language.
-
The Mitum blockchain operates on a multi-sig account basis. However, for user convenience, single-sig is prioritized.
-
Name the method so that it can be called intuitively from the user's perspective.
-
For consistency, method names use camel notation.
-
To eliminate confusion about the singular/plural representation of method names, we unify the singular notation.
The exception is when there are more than one method with the same function and the return value is singular and plural.
Unless there is a special purpose, it is more convenient to use the npm package rather than using the source code directly.
# Both ESM and CJS are available.
$ npm i @mitumjs/mitumjs
$ npm i
You can import and use TypeScript as is, but you can also build it with JavaScript and use it.
- Both commonjs (cjs) and ES2020 (esm) are available.
$ git clone https://github.com/ProtoconNet/mitumjs.git
# or
$ git clone [email protected]:ProtoconNet/mitumjs.git
$ cd mitumjs
$ npm i
# run build, if you want cjs or esm module
$ npm run build
-
After running build, a directory
dist
includebundle.cjs.cjs
andbundle.esm.mjs
files will be created. -
This is an example of how to 'require' a CJS module.
Enter an RPC-URL to communicate with the node.
You can omit the RPC-URL if you don't need to communicate with the node (for example, to generate a simple key pair or an operation for signing).
You can set the RPC-URL as shown below.
//cjs_test.cjs
const { Mitum } = require("./dist/bundle.cjs.cjs");
const mitum = new Mitum(/* "RPC-URL" */);
// You can set the RPC-URL as shown below.
const rpcurl = "http://127.0.0.1:54320";
mitum.setNode(rpcurl);
-
This is an example of using an ESM module by 'importing' it.
Some of the modules used for cryptography are CommonJS modules and may not support all module.exports as named exports.
⚠️ So you have to fix that part manually.The rest of the usage is the same, except for the syntax to 'import' the Mitum module at the beginning.
Open the bundle.esm.mjs
files and fix below lines.
//line 5
import { sha3_256, keccak256 as keccak256$1 } from 'js-sha3';
//line 14
import { ec } from 'elliptic';
The above lines need to be fix like below
//line 5
import pkg from 'js-sha3';
const { sha3_256, keccak256: keccak256$1 } = pkg;
//line 14
import pkg2 from 'elliptic';
const { ec } = pkg2;
In other words, the Import part of bundle.esm.mjs should be as follows.
import Int64 from 'int64-buffer';
import bigInt from 'big-integer';
import axios from 'axios';
import base58 from 'bs58';
import pkg2 from 'js-sha3';
const { sha3_256, keccak256: keccak256$1 } = pkg2;
import { Wallet } from 'ethers';
import secureRandom from 'secure-random';
import { hmac } from '@noble/hashes/hmac';
import { sha256 as sha256$1 } from '@noble/hashes/sha256';
import * as secp256k1 from '@noble/secp256k1';
import { getPublicKey } from '@noble/secp256k1';
import * as crypto from 'crypto';
import pkg from 'elliptic';
const { ec } = pkg;
After fix the builded file, you can import Mitum
like below
//esm_test.mjs
import Mitum from "./dist/esm_test.mjs";
const mitum = new Mitum(/* "RPC-URL" */);
⚠️ NoteIf you want to specify whether to use CommonJS or ESM in your package, add the following entry in the
package.json
:
"type": "commonjs"
or"type": "module"
.
Also, consider explicitly specifying the file extension as.cjs
or.mjs
rather than.js
in the execution file.
Important note about using functions :
The operation of Mitum is a transaction ‘message’.
Thus if function returns an operation object, remember that you haven't sent an operation to the network.
Any operation returned by the function is a raw transaction object, which requires additional signing.
Signed operation object must be sent to the network via the operation.send() function. (This is similar to web3.js and ethers.js).
Futher etailed information on how to use each function and the contract model can be found at the link below.
Be sure to check it out before using SDK.