Playboi.eth
6 min readOct 17, 2023

How to create a basic Ethereum wallet using QuickNode RPC.

Prerequisites:

  • Basic Knowledge of Ethereum.
  • What is JavaScript.
  • Node.js Installed.

WHAT IS ETHEREUM

Ethereum is a network of computers all over the world that follow a set of rules called the Ethereum protocol. The Ethereum network acts as the foundation for communities, applications, organizations and digital assets that anyone can build and use.

You can create an Ethereum account from anywhere, at any time, and explore a world of apps or build your own. The core innovation is that you can do all this without trusting a central authority that could change the rules or restrict your access.

WHAT IS JAVASCRIPT?

JavaScript is a widely used programming language primarily known for its capability to add interactivity and dynamic behavior to websites. It is one of the core technologies for building web applications alongside HTML (Hypertext Markup Language) and CSS (Cascading Style Sheets).

Here are some key points about JavaScript:

  1. Client-Side Language: JavaScript is primarily executed on the client’s browser. This means that it runs in the user’s device, allowing for dynamic updates and interactions without requiring a page reload.
  2. Multi-Paradigm Language: JavaScript supports multiple programming paradigms, including procedural, object-oriented, and functional programming. This makes it versatile and adaptable to different coding styles.
  3. High-level Language: It’s considered a high-level language because it’s designed to be relatively human-readable and doesn’t require direct management of system resources.
  4. Interpreted Language: JavaScript is an interpreted language, which means that it doesn’t need to be compiled before execution. The browser’s JavaScript engine reads the code and executes it directly.
  5. Dynamic Typing: JavaScript is dynamically typed, which means that you don’t need to specify the data type of a variable explicitly. The type of data a variable holds can change during the execution of a program.
  6. Cross-Platform: JavaScript is supported by all modern web browsers, making it a cross-platform language. This means that code written in JavaScript will work on different operating systems (like Windows, macOS, Linux) as long as the browser supports it.
  7. Used in Web Development: JavaScript is a crucial technology in web development. It’s used for tasks like adding interactivity to websites, creating dynamic content, manipulating the DOM (Document Object Model), and handling asynchronous operations.
  8. Frameworks and Libraries: There are many popular JavaScript libraries and frameworks like React, Angular, and Vue.js that provide pre-written code to help streamline and simplify common tasks.
  9. Server-Side JavaScript: While JavaScript is primarily known for client-side scripting, it can also be used on the server-side through platforms like Node.js. This allows developers to build full-stack applications using only JavaScript.
  10. ECMAScript: ECMAScript is the standard upon which JavaScript is based. JavaScript follows the ECMAScript specifications, and different versions (like ES5, ES6, ES7, etc.) introduce new features and improvements.

In this article, we are going to be building an Ethereum wallet using QuickNode RPC . Let's go.

STEP 1: Set up the project’s structure & Install necessary Dependencies.

Firstly, we have to create a create a file folder for our project.

  • Open up your Git-bash and type the following in it.
 mkdir custom-ethereum-wallet
cd custom-ethereum-wallet
code .

Automatically, it opens up your vscode after inputting the above in the terminal.

  • Initialize a new Node.js project in your Vscode Terminal.
npm init -y
  • Install the required dependencies.
  • libraries such as ethereum.js-wallet for wallet management and web3.js for Ethereum interaction are needed. Install them using npm:
npm install ethereumjs-wallet web3

STEP 2: Create a JavaScript file (wallet.js) for implementing essential wallet functions like generating Ethereum addresses, signing transactions, and checking balances. And put the following code in:

const Wallet = require('ethereumjs-wallet');
const Web3 = require('web3');

// Initialize Web3 with your Ethereum node's URL
const web3 = new Web3('QuickNode RPC'); // Replace with your QuickNode URL

// Function to generate a new Ethereum address and private key
function generateWallet() {
const wallet = Wallet.generate();
return {
address: wallet.getAddressString(),
privateKey: wallet.getPrivateKeyString(),
};
}

// Function to check the Ethereum balance of an address
async function checkBalance(address) {
try {
const balanceWei = await web3.eth.getBalance(address);
return web3.utils.fromWei(balanceWei, 'ether');
} catch (error) {
console.error(error);
return 'Error';
}
}

// Function to sign a transaction
async function signTransaction(privateKey, transactionData) {
try {
const wallet = Wallet.fromPrivateKey(Buffer.from(privateKey, 'hex'));
const signedTx = wallet.signTransaction(transactionData);
return signedTx;
} catch (error) {
console.error(error);
return null;
}
}

module.exports = { generateWallet, checkBalance, signTransaction };

How to get the QuickNode URL? Navigate through the website to the Dashboard platform and click on the ‘Endpoints’.

Copy the ‘HTTP Provider’.

STEP 3 : Create a Basic User Interface for Wallet Management.

You can create a basic HTML file (e.g., index.html) and a JavaScript file (e.g., app.js) for your user interface. Use HTML/CSS for the design and JavaScript to interact with your wallet functions (wallet.js). Here's a simplified example:

<!-- index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Custom Ethereum Wallet</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>Custom Ethereum Wallet</h1>
<button id="generateWallet">Generate Wallet</button>
<div id="walletInfo"></div>
<button id="checkBalance">Check Balance</button>
<div id="balanceInfo"></div>
<button id="signTransaction">Sign Transaction</button>
<div id="transactionInfo"></div>
<script src="app.js"></script>
</body>
</html>
// app.js
const { generateWallet, checkBalance, signTransaction } = require('./wallet');

const generateWalletButton = document.getElementById('generateWallet');
const walletInfoDiv = document.getElementById('walletInfo');
const checkBalanceButton = document.getElementById('checkBalance');
const balanceInfoDiv = document.getElementById('balanceInfo');
const signTransactionButton = document.getElementById('signTransaction');
const transactionInfoDiv = document.getElementById('transactionInfo');

generateWalletButton.addEventListener('click', () => {
const wallet = generateWallet();
walletInfoDiv.innerHTML = `
<p>Address: ${wallet.address}</p>
<p>Private Key: ${wallet.privateKey}</p>
`;
});

checkBalanceButton.addEventListener('click', async () => {
const address = prompt('Enter an Ethereum address to check its balance:');
if (address) {
const balance = await checkBalance(address);
balanceInfoDiv.textContent = `Balance: ${balance} ETH`;
}
});

signTransactionButton.addEventListener('click', async () => {
const privateKey = prompt('Enter your private key:');
if (privateKey) {
const transactionData = {
to: '0xRecipientAddress',
value: '1000000000000000', // 0.001 ETH in wei
gas: '21000',
gasPrice: '20000000000', // 20 Gwei
};

const signedTx = await signTransaction(privateKey, transactionData);
if (signedTx) {
transactionInfoDiv.textContent = `Signed Transaction: ${signedTx.rawTransaction}`;
} else {
transactionInfoDiv.textContent = 'Transaction signing failed.';
}
}
});

Step 4: Test Your Custom Wallet

To test your custom wallet, follow these steps:

  1. Serve your HTML and JavaScript files using a local development server or any hosting solution.
  2. Access your wallet’s user interface through a web browser.
  3. Use the interface to generate wallets, check balances, and sign transactions. Make sure to use testnet Ether and addresses for initial testing before handling real funds.
  4. Test your wallet with real or test Ethereum networks.

This basic custom Ethereum wallet provides a starting point for any basic Ethereum wallet development.

Playboi.eth

22y/o smart contract engineer. Advocate @graphprotocol, Ambassador @quicknode, Contributor @girscriptsoc . prev @web3_Nados, @blockchain