Getting started
The P2P.ORG Signer SDK allows you to sign transactions for 15+ networks using a unified interface. This guide demonstrates how to configure a signer and sign an Ethereum-based transaction using the Hoodi testnet as an example.
1. Installation
Install the Signer SDK NPM package. Refer to this link for more information.
2. Configuration
To initialize a signer, you need two sets of data: your Signer Configuration (sensitive keys) and your Network Parameters (RPC and public addresses).
// 1. Signer Config: Contains sensitive private keys and network targeting
const signerConfig = {
ethereumPrivateKey: process.env.PRIVATE_KEY, // e.g., '0x...'
networkName: 'hoodi', // Use 'mainnet' for production or 'hoodi' for testnet
};
// 2. Network Parameters: Public data for transaction preparation
const parameters = {
apiBase: 'https://api-test.p2p.org/api/v1',
token: 'YOUR_P2P_API_TOKEN',
rpcURL: 'https://ethereum-hoodi-rpc.publicnode.com',
walletAddress: '0x88bf...'
};3. Signing a transaction
The following function illustrates the standard workflow: fetching a fresh nonce from the blockchain, initializing the factory, and signing the payload.
import { SignerFactory, Signers } from '@p2p-org/signer-sdk';
import { ethers } from 'ethers';
/**
* @param unsignedTransactionData - The transaction object received from the Staking API
*/
async function signTransaction(unsignedTransactionData) {
// A. Prepare the provider to fetch on-chain metadata
const provider = new ethers.providers.JsonRpcProvider(parameters.rpcURL);
// B. Ensure the transaction has the correct Nonce for the wallet
unsignedTransactionData['nonce'] = await provider.getTransactionCount(parameters.walletAddress);
// C. Create a typed signer instance using the SignerFactory
// We specify 'Signers.Ethereum' to handle EVM-compatible logic
const signer = SignerFactory.createSigner(Signers.Ethereum, signerConfig);
// D. Sign the transaction locally
// The private key never leaves your environment
const signedTx = await signer.sign(unsignedTransactionData);
return signedTx;
}Updated 1 day ago