Skip to content

Quick Start

Installation

npm install signet.js
# or
yarn add signet.js
# or
pnpm add signet.js

Signing a Transaction

Here's a basic example using the EVM implementation:

import { utils, EVM } from 'signet.js'
import { createPublicClient, createWalletClient, http } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { sepolia } from 'viem/chains'
 
const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`)
 
const publicClient = createPublicClient({
  chain: sepolia,
  transport: http(),
})
 
const walletClient = createWalletClient({
  account,
  chain: sepolia,
  transport: http(),
})
 
const chainSigContract = new utils.chains.evm.ChainSignatureContract({
  publicClient,
  walletClient,
  contractAddress: utils.constants.CONTRACT_ADDRESSES.ETHEREUM
    .TESTNET_DEV as `0x${string}`,
})
 
const evm = new EVM({
  rpcUrl: 'https://sepolia.infura.io/v3/YOUR-PROJECT-ID',
  contract: chainSigContract,
})
 
const path = 'eth'
const predecessorId = walletClient.account.address
 
const { address: from, publicKey } = await evm.deriveAddressAndPublicKey(
  predecessorId,
  path
)
 
const { balance, decimals } = await evm.getBalance(from)
 
const { transaction, hashesToSign } = await evm.prepareTransactionForSigning({
  from: from as `0x${string}`,
  to: '0x4174678c78fEaFd778c1ff319D5D326701449b25',
  value: 1n, // Amount in wei (1 wei in this example)
})
 
const rsvSignature = await chainSigContract?.sign({
  payload: hashesToSign[0],
  path,
  key_version: 0, // The version of the key to use (usually 0)
})
 
const tx = evm.finalizeTransactionSigning({
  transaction,
  rsvSignatures: [rsvSignature],
})
 
const txHash = await evm.broadcastTx(tx)

Supported Chains

Architecture

The library is built around a core Chain interface that defines common functionality across all supported blockchain networks. Each specific chain implementation extends this interface with network-specific features while maintaining a consistent API.

For more details check the Chain page.

Utility Functions

Besides the Chain classes the library also provide utility functions to assist you on building transactions, requesting signature in wrapped methods.

Currently we support:

  • Near
  • EVM

Repositories