Sending transactions on the Ethereum blockchain is a foundational skill for any blockchain developer. Whether you're transferring ETH, interacting with smart contracts, or building decentralized applications, understanding the end-to-end process—create, sign, and broadcast—is essential. This guide walks you through each step using the Alchemy SDK and best practices for secure transaction handling.
We’ll focus on backend transaction signing, ideal for server-side applications. If you're building frontend integrations, tools like MetaMask act as browser-based signers—however, that’s beyond the scope of this article.
Understanding Ethereum Transaction Basics
Before diving into code, let’s clarify key concepts that often confuse new developers.
🔐 Alchemy Does Not Store Private Keys
Alchemy provides powerful node infrastructure but does not store or access your private keys. This design prioritizes security: no third party should ever hold your keys. You remain fully responsible for key management.
While Alchemy’s API allows reading from the blockchain, writing (i.e., sending transactions) requires you to sign them first—either via an external wallet or using the Alchemy SDK's built-in Wallet class, which runs locally and never exposes your key.
👉 Get started securely with a trusted platform today.
🧑💼 What Is a Signer?
A signer is an object or service that signs transactions using your private key. In this tutorial, we use the Alchemy SDK’s Wallet class as our signer. On the frontend, tools like MetaMask serve the same purpose by prompting users to approve and sign transactions directly in-browser.
✍️ Why Sign Transactions?
Every Ethereum transaction must be cryptographically signed to prove ownership and intent. The signature confirms that the sender controls the private key associated with the sending address. Without a valid signature, the network rejects the transaction outright.
🔑 How to Protect Your Private Key
Never expose your private key in code, logs, or public repositories. Best practices include:
- Storing keys in
.envfiles (as used here) - Using encrypted keystore files
- Leveraging hardware wallets or secure key management services
We’ll use environment variables via dotenv to keep credentials safe during development.
💻 What Is a Web3 Library?
Web3 libraries enable interaction with Ethereum nodes by abstracting low-level JSON-RPC calls. The Alchemy SDK is a modern, feature-rich wrapper optimized for JavaScript/Node.js environments, simplifying tasks like transaction sending, event listening, and gas estimation.
Step-by-Step Guide to Sending an Ethereum Transaction
Ensure you have:
- An Alchemy account
- A Metamask wallet with Sepolia ETH
- Node.js and npm installed
Let’s begin.
1. Create an Alchemy App on Sepolia Testnet
Log into your Alchemy Dashboard and create a new app. Select Sepolia as the network. This gives you a unique API endpoint to interact with the testnet.
2. Get Sepolia ETH from a Faucet
Visit the Alchemy Sepolia Faucet and request test ETH. Make sure to enter your Sepolia network address, not a mainnet or other testnet address. Confirm receipt in your wallet before proceeding.
3. Set Up Your Project Directory
Open your terminal and run:
mkdir ethereum-tx && cd ethereum-txThis creates and navigates into a fresh project folder.
4. Install Required Packages
Install the Alchemy SDK and dotenv for environment variable management:
npm install alchemy-sdk dotenv5. Create and Configure .env File
Create a .env file in your project root:
API_KEY="your-alchemy-api-key"
PRIVATE_KEY="your-wallet-private-key"Replace values with:
API_KEY: Found on your Alchemy app dashboard under "View Key"PRIVATE_KEY: Exported securely from MetaMask (never share it)
Ensure .env is added to .gitignore if committing code.
6. Write the Transaction Script (sendTx.js)
Create sendTx.js and add the following:
require('dotenv').config();
const { Alchemy, Network, Wallet } = require('alchemy-sdk');
const settings = {
apiKey: process.env.API_KEY,
network: Network.ETH_SEPOLIA,
};
const alchemy = new Alchemy(settings);
const wallet = new Wallet(process.env.PRIVATE_KEY);
async function sendTransaction() {
const nonce = await alchemy.core.getTransactionCount(wallet.address);
const transaction = {
to: '0x31b98D14007bDEe637298086988A0bBd31184523', // Sepolia faucet address
value: '10000000000000000', // 0.01 ETH in wei
gasLimit: '21000',
maxFeePerGas: '50000000000', // 50 Gwei
nonce: nonce,
};
const rawTx = await wallet.signTransaction(transaction);
const txResponse = await alchemy.core.sendTransaction(rawTx);
console.log('Transaction sent:', txResponse.hash);
return txResponse.hash;
}
sendTransaction();Key Components Explained:
- Wallet: Holds your private key and signs transactions locally.
- Nonce: Ensures transaction order; retrieved via
getTransactionCount. - Gas Settings:
gasLimit(21,000 for simple transfers),maxFeePerGas(covers base + priority fee). - Value: Amount in wei (1 ETH = 1e18 wei).
- Raw Transaction: Signed hex string ready for broadcasting.
- sendTransaction: Broadcasts the signed transaction to the network.
💡 Note: The data field is optional and used when calling smart contracts or attaching messages.👉 Explore advanced transaction tools now.
7. Run the Script
In your terminal:
node sendTx.jsIf successful, you’ll see output like:
Transaction sent: 0xabc123...8. Monitor Your Transaction
Go to your Alchemy Mempool Watcher, select your app, and filter transactions. Search by:
- Transaction hash
- Recipient address (
0x31b98D14...)
You’ll see its status evolve from pending → mined (success) or dropped (failure). Click the hash to view details and explore on Etherscan.
🎉 Congratulations! You’ve just sent your first Ethereum transaction using the Alchemy SDK.
Frequently Asked Questions (FAQ)
Q: Can I send transactions without a private key?
A: No. Signing requires a private key to prove ownership. Never share it—use secure storage methods like environment variables or hardware wallets.
Q: What happens if I reuse a nonce?
A: Reusing a nonce causes transaction failure or replacement. Always increment it sequentially based on getTransactionCount.
Q: Why use Alchemy instead of running my own node?
A: Alchemy offers scalable, reliable infrastructure without the overhead of node maintenance—ideal for developers focusing on application logic.
Q: How do I check if my transaction succeeded?
A: Use Etherscan or Alchemy’s Mempool Watcher to confirm inclusion in a block and check status (status=1 means success).
Q: Can I speed up a stuck transaction?
A: Yes—resubmit with the same nonce but higher gas fees to replace the pending one.
Q: Is this method suitable for production apps?
A: Yes—with enhancements like encrypted key storage, retry logic, and error handling.
Next Steps
Mastering transaction flow opens doors to deeper blockchain development. Consider exploring:
- Smart contract interactions
- Event listening with webhooks
- Batch requests for efficiency
For hands-on practice, try deploying a Hello World smart contract next.
Core Keywords
ethereum transaction, send eth, alchemy sdk, blockchain development, web3 javascript, sign transaction, nonce ethereum, gas fee ethereum