Creating Your First Transaction

This guide walks you through the process of creating and sending your first transaction on the Ettios blockchain. You'll learn how to create different types of transactions, estimate gas, and monitor transaction status.

Prerequisites

Before you begin, make sure you have:

  • A wallet with Ettios Mainnet configured (see Wallet Setup)
  • Some ETTIA tokens to cover transaction fees
  • Basic familiarity with JavaScript and blockchain concepts

Understanding Transactions

A blockchain transaction is a data structure that represents a state change on the blockchain. There are three main types of transactions on Ettios:

ETTIA Transfers

Simple transactions that transfer ETTIA (the native currency) from one address to another.

Contract Deployments

Transactions that contain compiled smart contract bytecode for deployment on the blockchain.

Contract Interactions

Transactions that call functions on existing smart contracts to modify state or retrieve information.

Method 1: Sending a Transaction with MetaMask

The simplest way to send a transaction is through a wallet interface like MetaMask:

Step 1: Open MetaMask

Make sure MetaMask is set to the Ettios Mainnet network (Chain ID: 2237).

Step 2: Click "Send"

Open MetaMask and click the "Send" button to initiate a transaction.

Step 3: Enter Recipient Address

Enter the recipient's Ethereum address. Double-check this address to avoid sending funds to the wrong recipient.

Step 4: Enter Amount

Specify the amount of ETTIA you want to send. You can also adjust the gas settings if needed.

Step 5: Confirm and Sign

Review the transaction details and click "Confirm" to sign and broadcast the transaction to the network.

Method 2: Using ethers.js

For more programmatic control, you can use ethers.js to send transactions:

ethers.js Transaction Example
// Import ethers.js
const { ethers } = require("ethers");

// Connect to Ettios Mainnet
async function sendTransaction() {
  try {
    // For browser environments with MetaMask
    if (window.ethereum) {
      await window.ethereum.request({ method: 'eth_requestAccounts' });
      const provider = new ethers.providers.Web3Provider(window.ethereum);
      const signer = provider.getSigner();
      
      // Check if connected to Ettios Mainnet
      const network = await provider.getNetwork();
      if (network.chainId !== 2237) {
        console.error("Please connect to Ettios Mainnet");
        return;
      }
      
      // Get sender's address and balance
      const address = await signer.getAddress();
      const balance = await provider.getBalance(address);
      console.log("Your address:", address);
      console.log("Your balance:", ethers.utils.formatEther(balance), "ETTIA");
      
      // Recipient address - REPLACE WITH ACTUAL RECIPIENT
      const recipient = "0xRecipientAddressHere";
      
      // Amount to send - 0.01 ETTIA
      const amount = ethers.utils.parseEther("0.01");
      
      // Check if we have enough balance
      if (balance.lt(amount)) {
        console.error("Insufficient balance");
        return;
      }
      
      // Prepare transaction
      const tx = {
        to: recipient,
        value: amount,
        // Optional: Specify gas limit and price
        // gasLimit: 21000, // Standard gas limit for transfers
        // gasPrice: ethers.utils.parseUnits("1", "gwei")
      };
      
      console.log("Sending transaction...");
      
      // Send transaction
      const txResponse = await signer.sendTransaction(tx);
      console.log("Transaction hash:", txResponse.hash);
      
      // Wait for transaction to be mined
      console.log("Waiting for confirmation...");
      const receipt = await txResponse.wait();
      
      console.log("Transaction confirmed in block:", receipt.blockNumber);
      console.log("Gas used:", receipt.gasUsed.toString());
      
      // Fetch updated balance
      const newBalance = await provider.getBalance(address);
      console.log("New balance:", ethers.utils.formatEther(newBalance), "ETTIA");
      
      return receipt;
    } else {
      console.error("MetaMask is not installed");
    }
  } catch (error) {
    console.error("Error sending transaction:", error);
  }
}

// Call the function
sendTransaction();

Using a Private Key (Node.js Environment)

For scripts running in a Node.js environment, you can use a private key to sign transactions:

Private Key Transaction Example
// IMPORTANT: Never hardcode private keys in production code!
// This is for demonstration purposes only.

const { ethers } = require("ethers");

async function sendTransactionWithPrivateKey() {
  try {
    // Ettios Mainnet RPC URL
    const provider = new ethers.providers.JsonRpcProvider("https://rpc.ettiosblockchain.io");
    
    // Private key (NEVER hardcode in production)
    const privateKey = "YOUR_PRIVATE_KEY"; // Replace with your private key
    
    // Create a wallet instance
    const wallet = new ethers.Wallet(privateKey, provider);
    
    // Get sender's address and balance
    const address = wallet.address;
    const balance = await provider.getBalance(address);
    console.log("Your address:", address);
    console.log("Your balance:", ethers.utils.formatEther(balance), "ETTIA");
    
    // Recipient address - REPLACE WITH ACTUAL RECIPIENT
    const recipient = "0xRecipientAddressHere";
    
    // Amount to send - 0.01 ETTIA
    const amount = ethers.utils.parseEther("0.01");
    
    // Check if we have enough balance
    if (balance.lt(amount)) {
      console.error("Insufficient balance");
      return;
    }
    
    // Get current gas price
    const gasPrice = await provider.getGasPrice();
    console.log("Current gas price:", ethers.utils.formatUnits(gasPrice, "gwei"), "gwei");
    
    // Prepare transaction
    const tx = {
      to: recipient,
      value: amount,
      gasLimit: 21000, // Standard gas limit for transfers
      gasPrice: gasPrice
    };
    
    console.log("Sending transaction...");
    
    // Send transaction
    const txResponse = await wallet.sendTransaction(tx);
    console.log("Transaction hash:", txResponse.hash);
    
    // Wait for transaction to be mined
    console.log("Waiting for confirmation...");
    const receipt = await txResponse.wait();
    
    console.log("Transaction confirmed in block:", receipt.blockNumber);
    console.log("Gas used:", receipt.gasUsed.toString());
    
    // Fetch updated balance
    const newBalance = await provider.getBalance(address);
    console.log("New balance:", ethers.utils.formatEther(newBalance), "ETTIA");
    
    return receipt;
  } catch (error) {
    console.error("Error sending transaction:", error);
  }
}

// Call the function
sendTransactionWithPrivateKey();

Security Warning

Never hardcode private keys in your code, especially in frontend applications. Always use secure key management or wallet connectors like MetaMask for production applications.

Method 3: Using web3.js

If you prefer web3.js, here's how to send a transaction:

web3.js Transaction Example
// Import Web3
const Web3 = require('web3');

// Connect to Ettios Mainnet
async function sendTransaction() {
  try {
    // For browser environments with MetaMask
    if (window.ethereum) {
      await window.ethereum.request({ method: 'eth_requestAccounts' });
      const web3 = new Web3(window.ethereum);
      
      // Check if connected to Ettios Mainnet
      const networkId = await web3.eth.net.getId();
      if (networkId !== 2237) {
        console.error("Please connect to Ettios Mainnet");
        return;
      }
      
      // Get accounts
      const accounts = await web3.eth.getAccounts();
      const sender = accounts[0];
      
      // Get sender's balance
      const balance = await web3.eth.getBalance(sender);
      console.log("Your address:", sender);
      console.log("Your balance:", web3.utils.fromWei(balance, 'ether'), "ETTIA");
      
      // Recipient address - REPLACE WITH ACTUAL RECIPIENT
      const recipient = "0xRecipientAddressHere";
      
      // Amount to send - 0.01 ETTIA
      const amount = web3.utils.toWei('0.01', 'ether');
      
      // Check if we have enough balance
      if (Number(balance) < Number(amount)) {
        console.error("Insufficient balance");
        return;
      }
      
      // Get gas price
      const gasPrice = await web3.eth.getGasPrice();
      
      // Prepare transaction
      const tx = {
        from: sender,
        to: recipient,
        value: amount,
        gas: 21000, // Standard gas limit for transfers
        gasPrice: gasPrice
      };
      
      console.log("Sending transaction...");
      
      // Send transaction
      const receipt = await web3.eth.sendTransaction(tx);
      
      console.log("Transaction hash:", receipt.transactionHash);
      console.log("Transaction confirmed in block:", receipt.blockNumber);
      console.log("Gas used:", receipt.gasUsed);
      
      // Fetch updated balance
      const newBalance = await web3.eth.getBalance(sender);
      console.log("New balance:", web3.utils.fromWei(newBalance, 'ether'), "ETTIA");
      
      return receipt;
    } else {
      console.error("MetaMask is not installed");
    }
  } catch (error) {
    console.error("Error sending transaction:", error);
  }
}

// Call the function
sendTransaction();

Tracking Transaction Status

After sending a transaction, you can track its status using the transaction hash:

Transaction Status Tracking
const { ethers } = require("ethers");

async function checkTransactionStatus(txHash) {
  try {
    // Connect to Ettios Mainnet
    const provider = new ethers.providers.JsonRpcProvider("https://rpc.ettiosblockchain.io");
    
    // Get transaction details
    const tx = await provider.getTransaction(txHash);
    
    if (!tx) {
      console.log("Transaction not found - it might be invalid or not yet broadcast");
      return null;
    }
    
    console.log("Transaction details:");
    console.log("From:", tx.from);
    console.log("To:", tx.to);
    console.log("Value:", ethers.utils.formatEther(tx.value), "ETTIA");
    console.log("Gas price:", ethers.utils.formatUnits(tx.gasPrice, "gwei"), "gwei");
    console.log("Gas limit:", tx.gasLimit.toString());
    
    // Check if transaction is confirmed
    if (tx.blockNumber) {
      console.log("Status: Confirmed in block", tx.blockNumber);
      
      // Get transaction receipt for more details
      const receipt = await provider.getTransactionReceipt(txHash);
      console.log("Gas used:", receipt.gasUsed.toString());
      console.log("Status:", receipt.status === 1 ? "Success" : "Failed");
      
      return receipt;
    } else {
      console.log("Status: Pending - not yet included in a block");
      
      // Optional: Wait for transaction to confirm
      console.log("Waiting for confirmation...");
      const receipt = await provider.waitForTransaction(txHash);
      console.log("Transaction confirmed in block:", receipt.blockNumber);
      console.log("Status:", receipt.status === 1 ? "Success" : "Failed");
      
      return receipt;
    }
  } catch (error) {
    console.error("Error checking transaction status:", error);
    return null;
  }
}

// Usage: Replace with your transaction hash
checkTransactionStatus("0xYourTransactionHashHere");

You can also track transaction status using the Ettios block explorer:

Ettios Mainnet Explorer

Visit the block explorer and search for your transaction hash:

Go to Explorer

Gas and Transaction Fees

On Ettios, every transaction requires a small fee paid in ETTIA. This fee is calculated as:

Transaction Fee = Gas Used × Gas Price

Gas Used

The amount of computational work required to process the transaction. Standard ETTIA transfers use 21,000 gas, while contract interactions use variable amounts.

Gas Price

The price you're willing to pay per unit of gas, specified in gwei (1 gwei = 0.000000001 ETTIA). Higher gas prices mean faster transaction confirmation.

Estimating Gas

For contract interactions, it's recommended to estimate the gas required before sending a transaction:

Gas Estimation Example
const { ethers } = require("ethers");

async function estimateGas() {
  try {
    // Connect to provider
    const provider = new ethers.providers.Web3Provider(window.ethereum);
    const signer = provider.getSigner();
    
    // Recipient address
    const recipient = "0xRecipientAddressHere";
    
    // Amount to send - 0.01 ETTIA
    const amount = ethers.utils.parseEther("0.01");
    
    // Prepare transaction object
    const tx = {
      to: recipient,
      value: amount,
    };
    
    // Estimate gas
    const estimatedGas = await provider.estimateGas(tx);
    console.log("Estimated gas:", estimatedGas.toString());
    
    // Get current gas price
    const gasPrice = await provider.getGasPrice();
    console.log("Current gas price:", ethers.utils.formatUnits(gasPrice, "gwei"), "gwei");
    
    // Calculate estimated fee
    const estimatedFee = estimatedGas.mul(gasPrice);
    console.log("Estimated fee:", ethers.utils.formatEther(estimatedFee), "ETTIA");
    
    return estimatedGas;
  } catch (error) {
    console.error("Error estimating gas:", error);
  }
}

estimateGas();