A TypeScript library for creating transactions for different chains and signing them with NEAR's MPC (Multi-party Computation)service.
This library provides a unified interface for interacting with different blockchain networks through a common set of methods. It uses MPC for secure key management and transaction signing.
The library provides chain adapters for the following blockchain networks:
Each chain adapter provides a unified interface for:
npm install chainsig.js
# or
yarn add chainsig.js
# or
pnpm add chainsig.js
Examples for sending transfers and function calls with chainsig.js via a NEAR wallet can be found in the near-multichain repo, along with in depth documentation in the NEAR docs.
Examples for sending transfers with chainsig.js via near-api-js/near-js can be found in the examples folder.
Full typedocs for the library can be found here.
Because of underlying dependencies, this library is a Commonjs project. You may need to configure your projects to use this library.
Here are simple examples in TypeScript and JavaScript.
import { chainAdapters, contracts } from "chainsig.js";
import { KeyPair, type KeyPairString } from "@near-js/crypto";
import { createPublicClient, http } from "viem";
import { mainnet } from "viem/chains";
// Initialize NEAR connection with credentials from environment
const accountId = process.env.NEAR_ACCOUNT_ID;
const privateKey = process.env.NEAR_PRIVATE_KEY as KeyPairString;
if (!accountId || !privateKey) {
throw new Error(
"NEAR_ACCOUNT_ID and NEAR_PRIVATE_KEY must be set in environment",
);
}
const keypair = KeyPair.fromString(privateKey);
const contract = new contracts.near.ChainSignatureContract({
networkId: "testnet",
contractId: "v1.signer-prod.testnet",
accountId,
keypair,
});
const publicClient = createPublicClient({
chain: mainnet,
transport: http(),
});
const evmChain = new chainAdapters.evm.EVM({
publicClient,
contract,
});
// Derive address and public key
const { address, publicKey } = await evmChain.deriveAddressAndPublicKey(
accountId,
"any_string",
);
// Check balance
const { balance, decimals } = await evmChain.getBalance(address);
// Create and sign transaction
const { transaction, hashesToSign } =
await evmChain.prepareTransactionForSigning({
from: "0x...",
to: "0x...",
value: 1n,
});
// Sign with MPC
const signature = await contract.sign({
payload: hashesToSign[0].payload,
path: "any_string",
key_version: 0,
});
// Add signature
const signedTx = evmChain.finalizeTransactionSigning({
transaction,
rsvSignatures: [signature],
});
// Broadcast transaction
const txHash = await evmChain.broadcastTx(signedTx);