LogoLogo
Blockchain ExplorerWebsiteGitHubSmart ContractsCertikCoinMarketCap
  • 🚀Metacces is coming !!!
  • 🎯Mission & Vision
  • 📈Market Analysis
  • 🤝Partnerships
  • METACCES: GENERAL
    • 🎮AR/VR Game
      • 👉Introduction
      • 🔑Key features
      • 📈Earning mechanics
      • 👽Unique Oli AI
      • 🧬Blacxes
        • What is Blacxes
        • Utilites
        • Unique DNA
        • DAO Governance
        • Technology
        • Distribution
        • Swap
      • ⛓️Bridging Web2 Simplicity with Web3 Power
      • 🚀How Does Metacces Outperform the Competition?
      • 🎮Game Structure
        • Origin Story: Oli & the Blacxes
        • Game theme (Access Journey)
          • Overview
          • Basic level
          • Intermediate level
          • Final level
        • Activities and Gameplay
        • Game seasons
          • Introduction
          • Season Concept
          • What Does Each Season Include?
          • Importance of Seasons in Metacces
        • Skins & Tools
          • Introduction
          • Core Principles
          • Core Uses of Tools
          • Main Categories of Tools
          • Rarity and Value
          • Symbolism of Tools
          • Verification and Security Mechanisms
        • Clans
          • Introduction
          • Core Pillars of the Clan System
          • Clan Activities
          • Ownership and Economy Within the Clan
          • The Reputation System
          • The Future of Clans in Metacces
          • How to Create a Clan in Metacces
    • ⛓️Blockchain Layer 1
      • Developers
        • Public Endpoints
        • MetaMask
        • Node Setup
        • JSON RPC Server
        • Connect to RPC
        • API Methods
        • Client Libraries
        • Smart Contracts
          • Deploy
          • Interact
          • Transfer
          • Fixed Cap Asset
          • Variable Cap Asset
  • 👽Oli AI Agent
  • 📱Oli Gen
  • 🪙Acces Coin
    • Coin Utility
    • Smart-Contracts
    • Tokenomecs
    • Metacces Listings Roadmap
  • DEVELOPMENT
  • 📅Roadmap
    • Main Roadmap
      • ✔️2022
      • ✔️2023
      • 🔛2024
      • 2025
    • Coin Roadmap
      • 2022
      • 2023
      • 2024
  • TEAM
    • 7️⃣Core 7 values
    • 👨‍🚀Meet The Team
  • SECURITY
    • 🫂 Team KYC Gold Verified by CERTIK (2024)
    • 🪙Coin Audit by CERTIK
    • 🗓️Smart Contract Vesting Audit by CERTIK
    • 🪙Coin Audit by SOLIDPROOF
    • 🪙Coin Audit by HACKEN
  • OTHER INFO
    • Contact Us
    • Community
      • Website
      • Telegram
      • X.Twitter
      • Discord
      • Youtube
      • Instagram
      • Facebook
Powered by GitBook
On this page

Was this helpful?

  1. METACCES: GENERAL
  2. Blockchain Layer 1
  3. Developers
  4. Smart Contracts

Transfer

PreviousInteractNextFixed Cap Asset

Last updated 10 months ago

Was this helpful?

Using eth_sendSignedTransaction

The simplest way to transfer funds between externally-owned accounts is using eth_sendSignedTransaction. This example uses eth_sendSignedTransaction and one of the test accounts to transfer funds to a newly created account.

Create a new file eth_tx.js (or run the following commands in a JavaScript console) to send the transaction. Before making the transaction, the script checks the balances of both accounts to verify the funds transfer after the transaction.

eth_tx.js using eth_sendSignedTransaction

Copy

const web3 = new Web3(host);
// Pre-seeded account with 90000 ACCES
const privateKeyA =
  "0x8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63";
const accountA = web3.eth.accounts.privateKeyToAccount(privateKeyA);
var accountABalance = web3.utils.fromWei(
  await web3.eth.getBalance(accountA.address),
);
console.log("Account A has balance of: " + accountABalance);

// Create a new account to transfer ETH to
var accountB = web3.eth.accounts.create();
var accountBBalance = web3.utils.fromWei(
  await web3.eth.getBalance(accountB.address),
);
console.log("Account B has balance of: " + accountBBalance);

// Send 0x100 ACCES from AccountA to AccountB and sign the transaction with
// Account A's private key
const rawTxOptions = {
  nonce: web3.utils.numberToHex(
    await web3.eth.getTransactionCount(accountA.address),
  ),
  from: accountA.address,
  to: accountB.address,
  value: "0x100", // Amount of ACCES to transfer
  gasPrice: "0x0", 
  gasLimit: "0x24A22", // Max number of gas units the tx is allowed to use
};
console.log("Creating transaction...");
const tx = new Tx(rawTxOptions);
console.log("Signing transaction...");
tx.sign(Buffer.from(accountA.privateKey.substring(2), "hex"));
console.log("Sending transaction...");
var serializedTx = tx.serialize();
const pTx = await web3.eth.sendSignedTransaction(
  "0x" + serializedTx.toString("hex").toString("hex"),
);
console.log("tx transactionHash: " + pTx.transactionHash);

// After the transaction, check the updated balances and there should be some ACCES transferred
var accountABalance = await getAccountBalance(host, accountA);
console.log("Account A has an updated balance of: " + accountABalance);
var accountBBalance = await getAccountBalance(host, accountB);
console.log("Account B has an updated balance of: " + accountBBalance);

An alternative to using eth_sendSignedTransaction is using eth_sendTransaction.

Create a new file eth_tx.js (or run the following commands in a JavaScript console) to send the transaction.

eth_tx.js using eth_sendTransaction

Copy

const web3 = new Web3(host);
// Pre-seeded account with 90000 ETH
const privateKeyA =
  "0x8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63";
const accountA = web3.eth.accounts.privateKeyToAccount(privateKeyA);
var accountABalance = web3.utils.fromWei(
  await web3.eth.getBalance(accountA.address),
);
console.log("Account A has balance of: " + accountABalance);

// Create a new account to transfer ETH to
var accountB = web3.eth.accounts.create();
var accountBBalance = web3.utils.fromWei(
  await web3.eth.getBalance(accountB.address),
);
console.log("Account B has balance of: " + accountBBalance);

// Send some ETH from A to B
const txOptions = {
  from: accountA.address,
  to: accountB.address,
  value: "0x100", // Amount of ETH to transfer
  gasPrice: "0x0", 
  gasLimit: "0x24A22", // Max number of gas units the tx is allowed to use
};
console.log("Creating transaction...");
const pTx = await web3.eth.sendTransaction(txOptions);
console.log("tx transactionHash: " + pTx.transactionHash);

// After the transaction, there should be some ETH transferred
var accountABalance = await getAccountBalance(host, accountA);
console.log("Account A has an updated balance of: " + accountABalance);
var accountBBalance = await getAccountBalance(host, accountB);
console.log("Account B has an updated balance of: " + accountBBalance);

Using eth_sendTransaction

⛓️
​
​