Skip to content

yasenltd/sign-eth-txn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SignTxn

A utility for signing Ethereum transactions using different EIP standards (EIP-155, EIP-1559, EIP-2930).

Overview

SignTxn is a JavaScript-based tool that allows you to sign Ethereum transactions offline using different transaction types:

  • EIP-155: Legacy transactions with replay protection
  • EIP-1559: Fee market change transactions (London fork)
  • EIP-2930: Optional access lists transactions (Berlin fork)

This tool is useful for developers who need to create and sign transactions for testing, debugging, or interacting with Ethereum networks.

Project Structure

The project is organized into the following directories:

  • scripts/: Contains the transaction signing scripts for different EIP standards
    • sign-eip155-tx.js: Legacy transaction signing (EIP-155)
    • sign-eip1559-tx.js: Fee market transaction signing (EIP-1559)
    • sign-eip2930-tx.js: Access list transaction signing (EIP-2930)
  • helpers/: Contains utility functions used by the scripts
    • utils.js: Common utility functions for parsing method parameters and getting nonce
  • abi/: Contains ABI definitions for contract interactions

Installation

  1. Clone the repository:

    git clone https://github.com/yasenltd/SignTxn.git
    cd SignTxn
    
  2. Install dependencies:

    npm install
    
  3. Configure your environment variables by copying the .example.env file to .env and updating the values (see Configuration section below).

Usage

The repository contains three scripts for signing different types of transactions:

1. Sign EIP-155 Transaction (Legacy)

node scripts/sign-eip155-tx.js

2. Sign EIP-1559 Transaction (Fee Market)

node scripts/sign-eip1559-tx.js

3. Sign EIP-2930 Transaction (Access Lists)

node scripts/sign-eip2930-tx.js

Each script will output the signed transaction as a hexadecimal string that can be submitted to an Ethereum network.

Configuration

The repository includes a .example.env file with placeholder values. Copy this file to create your own .env file:

cp .example.env .env

Then edit the .env file to set your own values for the following variables:

PRIVATE_KEY=your_private_key_here
VALUE=0.001
CHAIN_ID=
GAS_LIMIT=
TARGET_CHAIN_ID=
TO_ADDRESS=0xYourTargetAddressHere
RPC_PROVIDER=https://your-rpc-endpoint.io

# ABI and Method Configuration
USE_METHOD=false
ABI_PATH=./abi/contract.json
METHOD_NAME=deposit
# Optional: Override recipient address (defaults to wallet address if not specified)
# RECIPIENT=0xYourRecipientAddress
# Optional: Override method parameters (JSON array format)
# METHOD_PARAMS=["0xYourRecipientAddress", "0x4268"]

Configuration Options

Variable Description Default
PRIVATE_KEY Your Ethereum private key (without 0x prefix) Required
VALUE Amount of ETH to send (in ETH) 0.0
CHAIN_ID Chain ID of the network 1
GAS_LIMIT Gas limit for the transaction 21000
TARGET_CHAIN_ID Target chain ID for cross-chain operations 0
TO_ADDRESS Recipient address (contract or EOA) Required
RPC_PROVIDER RPC endpoint URL Required
USE_METHOD Whether to create a contract method call false
ABI_PATH Path to the contract ABI JSON file ./abi/contract.json
METHOD_NAME Contract method name to call methodName
RECIPIENT Recipient address for the method call Wallet address
METHOD_PARAMS JSON array of parameters for the method call [RECIPIENT, TARGET_CHAIN_ID]

Examples

Simple ETH Transfer

To sign a simple ETH transfer transaction:

  1. Configure your .env file:

    PRIVATE_KEY=your_private_key_here
    VALUE=0.01
    TO_ADDRESS=0xRecipientAddressHere
    RPC_PROVIDER=https://mainnet.infura.io/v3/your-project-id
    CHAIN_ID=1
    USE_METHOD=false
    
  2. Run one of the signing scripts:

    node scripts/sign-eip1559-tx.js
    

Contract Method Call

To sign a transaction that calls a contract method:

  1. Configure your .env file:

    PRIVATE_KEY=your_private_key_here
    VALUE=0
    TO_ADDRESS=0xContractAddressHere
    RPC_PROVIDER=https://mainnet.infura.io/v3/your-project-id
    CHAIN_ID=1
    USE_METHOD=true
    METHOD_NAME=transfer
    METHOD_PARAMS=["0xRecipientAddress", "1000000000000000000"]
    
  2. Run one of the signing scripts:

    node scripts/sign-eip1559-tx.js
    

Ethereum JSON-RPC API Calls

The following curl commands can be used to interact with Ethereum nodes:

eth_sendRawTransaction

curl -X POST https://testnet.rpc.neuraprotocol.io \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "method": "eth_sendRawTransaction",
    "params": ["txnSignatureHex"],
    "id": 1
  }'

eth_getTransactionCount

curl -X POST https://testnet.rpc.neuraprotocol.io \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "method": "eth_getTransactionCount",
    "params": ["address", "pending"],
    "id": 1
  }'

eth_getCode

curl -X POST https://testnet.rpc.neuraprotocol.io \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "method": "eth_getCode",
    "params": ["address", "latest"],
    "id": 1
  }'

Method Reference Table

Method Purpose Input Required
eth_sendRawTransaction Send a signed TX to the chain Raw signed TX hex
eth_getTransactionCount Get the correct nonce for an account Address, block tag
eth_getCode Check if address is a contract Address, block tag (latest)

Security Notes

  • Never commit your .env file with your private key to version control (it's already added to .gitignore)
  • This tool is for development and testing purposes only
  • Always verify the transaction details before submitting to a network

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors