Do you Hardcode your Ethereum Wallets When Developing?

Do you Hardcode your Ethereum Wallets When Developing?

Sep 2, 2025

When I first started dabbling in Web3 development, one of the most common tasks I encountered was managing wallets. I quickly learned that ethers.js is an essential tool for interacting with the Ethereum blockchain. As a developer, I wanted to understand the library inside and out, so I started with the basics: creating a wallet.

For my local testing, I needed a simple way to create a wallet instance, and I soon discovered I could do this directly from a private key. It's a method that's perfect for a sandbox environment, though it's a huge "don't do this with real money" sign. I want to share the process I used and why it was so useful for my projects.


The Wallet from a Private Key: A Local Development Lifesaver

For local testing, I'm not dealing with real funds. I'm just running a local blockchain instance on my machine using tools like Hardhat or Ganache. The private keys from these local networks are publicly known, so there's no risk involved. This makes creating a wallet from a private key incredibly convenient. I can hardcode it in a script, run my tests, and then delete the file without any fear.

Here’s the simple script I wrote to make this happen:

// Step 1: Import the ethers library
const ethers = require("ethers");

// Step 2: Grab the private key for my local test account.
// I always make sure this is a test account and never
// a private key from a mainnet wallet.
const myTestPrivateKey = "0xac0974bec39a17e36ba4a6b4d2380603fb71676f2d93e1742442436d403e0591"; // Example from Hardhat

// Step 3: Connect to my local network's provider.
// This allows the wallet to "see" the blockchain.
const provider = new ethers.JsonRpcProvider("http://127.0.0.1:8545");

// Step 4: Create the wallet instance using the private key and provider.
const myWallet = new ethers.Wallet(myTestPrivateKey, provider);

// Now I can see the wallet's address and check its balance!
console.log("Wallet address:", myWallet.address);

async function checkBalance() {
  const balance = await myWallet.provider.getBalance(myWallet.address);
  console.log("Wallet balance:", ethers.formatEther(balance), "ETH");
}

checkBalance();


Why It's Perfect for Local Work (and Unsafe for Production)

The reason this method is so fantastic for local testing is its simplicity. There's no need to mess around with mnemonic phrases, encrypted JSON files, or complex key management systems. I can just plug in the private key, and I have a fully functional wallet ready to sign transactions and interact with my smart contracts.

However, I can't stress this enough: you should never, ever, use a private key from a live wallet in this way. A private key is the absolute key to your funds. If it's exposed, anyone can take your assets. In a real-world application, I would use secure methods like mnemonic phrases (backed up properly offline) or a hardware wallet.

For now, this simple technique is a powerful tool in my development workflow. It lets me move quickly, experiment with contracts, and build dApps with confidence, all while keeping my real assets safe and sound.

Let's Connect

Let's Grow Together

Web Design

Starting from $399.90

I design business and eCommerce websites using Webflow, Framer, and WordPress (Elementor).

Smart Contract Development

Starting from $459.50

I develop secure and efficient smart contracts using Solidity, tailored for Web3 applications and blockchain-based solutions.

UI/UX Design

Starting from $369

I craft intuitive and engaging user interfaces backed by user-centered UX design to enhance product usability and experience across.

Image banner

Let's Connect

Let's Grow Together

Web Design

Starting from $399.90

I design business and eCommerce websites using Webflow, Framer, and WordPress (Elementor).

Smart Contract Development

Starting from $459.50

I develop secure and efficient smart contracts using Solidity, tailored for Web3 applications and blockchain-based solutions.

UI/UX Design

Starting from $369

I craft intuitive and engaging user interfaces backed by user-centered UX design to enhance product usability and experience across.

Image banner

Let's Connect

Let's Grow Together

Web Design

Starting from $399.90

I design business and eCommerce websites using Webflow, Framer, and WordPress (Elementor).

Smart Contract Development

Starting from $459.50

I develop secure and efficient smart contracts using Solidity, tailored for Web3 applications and blockchain-based solutions.

UI/UX Design

Starting from $369

I craft intuitive and engaging user interfaces backed by user-centered UX design to enhance product usability and experience across.

Image banner

Create a free website with Framer, the website builder loved by startups, designers and agencies.