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 { contracts, constants, chainAdapters } 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 evmChainSigContract = new contracts.evm.ChainSignatureContract({
  publicClient,
  walletClient,
  contractAddress: constants.CONTRACT_ADDRESSES.ETHEREUM
    .TESTNET_DEV as `0x${string}`,
})
 
const evm = new chainAdapters.evm.EVM({
  publicClient,
  contract: evmChainSigContract,
})
 
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 evmChainSigContract?.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 ChainAdapter 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 ChainAdapter page.

Utility Functions

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

Currently we support:

  • Near
  • EVM

Repositories