Pharos Docs
  • Introduction
    • About Pharos Network
    • Vision & Mision
    • Why Pharos Network
    • Concepts
      • Degree of Parallelism (DP)
  • Architecture
    • Pharos Modular Stack
    • Node Architecture
      • About Pharos Nodes
  • Core Technologies
    • Pharos Consensus
    • Pharos Execution
      • Why A New Blockchain Compute Model
      • Pharos VM
    • Pharos Pipelining
    • Pharos Store
      • Why We Need a Blockchain-Native Store
    • Pharos SPNs
  • Network Overview
    • Pharos Networks
      • Pharos Testnet Information
    • Pharos Gas Model
    • FAQ
  • Node & Validator Guide
    • Validator Requirements
    • Validator Node Deployment
      • Using Docker (Devnet)
      • Using Docker (Testnet)
    • Node Management
    • Rapid Node Initialization
      • Rapid Node Initialization(Testnet)
      • Rapid Node Initialization(Devnet)
    • Pharos Network Snapshots
    • Node Debugging & Configuration
  • Pharos Node Monitoring
  • Developer Guide
    • Foundry
      • Write Your First dApp
      • Write Your First Token
      • Write Your First NFT
      • Write Your First Uniswap Contract
    • Hardhat
      • Write Your First dApp
      • Write Your First Token
      • Write Your First NFT
      • Write Your First Uniswap Contract
    • Rust
    • Interoperability
      • Call EVM From WASM
  • API & SDK
    • JSON-RPC API Methods
  • Resources
    • EVM
    • Solidity
Powered by GitBook
On this page
  • Write Your First Transaction
  • Prerequisites
  • Setup 1: Pick Your Favorite Contract Develop Framework and IDE
  • Setup 2: Set Up the Project
  • Step 3: Run the Script
  • Key Points
  • Troubleshooting
  • Conclusion
Export as PDF
  1. Developer Guide

Hardhat

PreviousWrite Your First Uniswap ContractNextWrite Your First dApp

Last updated 21 days ago

This guide is suitable for developers who want to start building dApps using Pharos and hardhat toolchains. If you are a new user of Ethereum, please consider researching the before continuing.

Write Your First Transaction

This guide will walk you through the process of sending your first transaction on the Pharos blockchain using three popular libraries: ethers.js, web3.js, and web3.py. By the end of this guide, you will understand how to send a transaction programmatically using these libraries.

Prerequisites

Before you begin, ensure you have the following:

  • Git: Used for code management and obtain examples.

  • Pharos Devnet/Testnet Access: Access to a Pharos node (local or remote) for interacting with the blockchain.

Setup 1: Pick Your Favorite Contract Develop Framework and IDE

Install your preferred contract framework from the below list:

  • ethers.js

  • web3.js

  • web3.py

Setup 2: Set Up the Project

Clone the example repo and add dependencies.

git clone https://github.com/PharosNetwork/examples
cd examples/transaction/ethersjs
npm install
const { ethers } = require("ethers");

// Connect to Pharos Testnet
const provider = new ethers.providers.JsonRpcProvider("<PHAROS_RPC_URL>");

// Note: Your wallet private key (for testnet only, never expose this in production)
const privateKey = "YOUR_PRIVATE_KEY";
const wallet = new ethers.Wallet(privateKey, provider);

// Transaction details
const tx = {
    to: "RECIPIENT_ADDRESS", // Note: Replace with the recipient's address
    value: ethers.utils.parseEther("0.1"), // Amount to send (0.1 PHAR)
};

// Send the transaction
wallet.sendTransaction(tx)
    .then((transaction) => {
        console.log("Transaction sent:", transaction.hash);
    })
    .catch((error) => {
        console.error("Error sending transaction:", error);
    });

Step 3: Run the Script

Run the script using Node.js:

node index.js

Key Points

  • Private Key: Never expose your private key in production. Use environment variables or secure storage.

  • Recipient Address: Replace RECIPIENT_ADDRESS with the actual recipient's wallet address.

  • Gas Limit: Ensure you include a sufficient gas limit for the transaction.

Troubleshooting

  • Transaction Fails: Ensure you have enough testnet tokens to cover the transaction fee.

  • Incorrect Network: Double-check that you are connected to the Pharos Testnet.

  • Invalid Address: Verify that the recipient's address is correct.

Conclusion

Now that you’ve sent your first transaction using ethers.js, web3.js, and web3.py.

This guide provides a comprehensive introduction to sending transactions on the Pharos blockchain using three popular libraries. If you encounter any issues, refer to the Troubleshooting section or consult the respective library's documentation. Happy building! 🚀

Ethereum documentation