This page may contain legacy content

To get our most up-to-date content please access our documentation

November 25, 2021

Ethereum Send Transaction Basics – Send Ethereum with One Line of Code

Table of Contents

Decentralized networks such as Ethereum have opened up a vast array of new opportunities for developers. Thanks to these networks, programmers can build new Web3 applications without any reliance on external monetary entities. This enables creators to replace cash with digital tokens and trade whatever they want without intermediaries. However, their dependency on Ethereum transactions means that they would need special services to operate reliably. For this purpose, the Ethereum Foundation developed “Web3.js”, which provides the necessary infrastructure and is the library of choice for blockchain developers. Moreover, you can use this library quickly and easily with Moralis’ Web3 platform, making the process of transferring, sending, and receiving ETH straightforward. As such, follow along as we teach you the basics regarding an Ethereum send transaction and how to send Ethereum with one line of code.

Moralis provides backend development infrastructure for you to deploy your dApps (decentralized applications) on popular blockchains such as Ethereum. Moralis’ SDK and its reliable nodes make a good mixture for building your blockchain projects. You can implement Moralis’ SDK to execute Ethereum authentication for your dApp’s users either through crypto wallets or ordinary methods. Moreover, the SDK lets you obtain users’ data, including balances, NFTs, events, or transactions. Before telling you about the simple Ethereum send transaction instructions using Moralis, we will dig into categories of Ethereum transactions. In the next stage, we will provide details on how you can integrate Ethereum transactions into dApps. Finally, we will talk about the gas fees and show you how to calculate transaction fees.

Ethereum Send Transaction – Why Moralis?

Developing dApps, despite its recent popularity, has its own complications. Creators should overcome the limitations of the available infrastructure and use primitive tools provided by the Ethereum Foundation. Furthermore, working with barebone frameworks such as Web3.js requires comprehensive knowledge of APIs, ABIs, and data structures. However, the Moralis SDK has removed the complexities from dApps and provided you with excellent infrastructure and tools. Thanks to its NFT API, Price API, and Moralis Speedy Nodes, developing Web3 applications is no longer rocket science.

Moralis’ workable solutions help you bypass the limitations of RPC nodes. The platform also provides cross-chain interoperability for your blockchain projects. In other words, it does not restrict you to a single blockchain. With just a few clicks, you can make your dApps compatible with popular chains out there. Currently, it supports Binance Smart Chain (BSC), Avalanche, Arbitrum, Polygon, and Solana and Elrond in the pipeline.

Ethereum Send Transaction Basics – Transaction Types

Ethereum is a decentralized network of computers, also known as nodes, with capabilities beyond transferring value. As the second-largest blockchain on earth, Ethereum has the required infrastructure for running applications. In other words, despite Bitcoin, with monetary usage only, developers can use Ethereum to run dApps on it. Bitcoin and Ethereum, though built on the same basis, are fundamentally different. While the former uses blockchain technology to transfer value, the latter takes it further and lets users build dApps.

The confirmation of Ethereum transactions happens within seconds, though it takes a few minutes for Bitcoin. After investigating the differences between the top two blockchains, it is time to delve into the concept of Ethereum transactions. 

Generally, every Ethereum transaction falls into one of three groups, as shown below:

  • Normal Transactions – Whenever an EOA (externally owned account) sends ETH to another EOA, we call it a “normal transaction”. EOAs are accounts held by humans rather than contracts and are usually called wallets. To check your blockchain transactions and analyze your projects, you need to have an account in a block explorer. Etherscan, Etherchain, and the “Blockchain” explorer from Ethereum are some of the well-known block explorers out there. If you are using Etherscan, you can check your “Normal Transactions” section under the “Transaction” tab. 
  • Internal Transactions – In these types of transactions, smart contracts play the role of an intermediary and transfer ETH between accounts. In Etherscan, you can see the internal transactions under the “Internal Txns” tab. 
  • Token Transfers – This category belongs to the transactions of tokens compatible with ERC-20 and ERC-721 protocols. You can check these transactions under the “ERC20 Token Txns” or “ERC721 Token Txns” tabs in Etherscan.  

Ethereum Send Transaction Basics – Token Standards Explained

As stated previously, Ethereum is a decentralized network of nodes based on tokens. On Ethereum, you can buy, sell and trade tokens, which are essentially smart contracts. They can either represent digital assets such as your song’s copyright or tangible real-world objects like your drawings. Moreover, ERC-20, ERC-721, and ERC-1155 are some popular token standards on Ethereum that we will elaborate on in this section.

ERC-20, which we use for fungible tokens, contains standards for creating smart contracts on Ethereum. The protocol defines tokens’ transfer method, the prerequisites for transactions’ approval, the total repository of tokens, and their access method. The token standard is prevalent, and more than 100 digital currencies use tokens compatible with the ERC-20 standard.

ERC-721 is a set of standards for defining NFTs and making them unique. ERC-721 compatible tokens are essentially non-fungible. In other words, they are not mutually interchangeable and represent items (digital or physical) that do not have counterparts. Just imagine two tokens that represent two pieces of art from Vincent van Gogh. It is not possible to change them with each other. Moreover, non-fungible tokens are the opposite of fungible tokens (those compatible with the ERC-20 standard). A good example is two bills of one dollar. They have the same value, and you can change them for each other.

ERC-1155 is a protocol with the best of both worlds since ERC1155 can represent both fungible and non-fungible tokens. Video games would be a good example of this token standard. In these games, you obtain points and buy new items (knife, rifle, or grenade) or change them with one another. In this case, ERC-721 would be the best option to represent both the fungible and non-fungible tokens.

How Does Ethereum Send Transaction Functionality Work?

Ethereum transactions happen on a particular blockchain network called “mainnet”. Decentralized applications running on Ethereum constantly send and receive transactions. To send these transactions on the mainnet, you have to spend real money, which is why developers use test networks (a.k.a “testnet”). These are networks that allow them to use Ethereum without having to spend real money. Furthermore, Rinkeby, Ropsten, and Kovan are common testnets on Ethereum. They play a critical role in the dApp’s development lifecycle. To use testnets, you’ll need a crypto wallet with an address. We suggest downloading MetaMask, which is a useful and popular wallet that can be used as a browser extension. To learn more about MetaMask and its functionality, read our previous article on Moralis’ blog: “MetaMask Explained – What is MetaMask?”.

As stated earlier, Ethereum sends transactions by smart contracts. These are pieces of code containing the agreements between the parties. To write the contract, you’ll need to build the data structures of your project from scratch. If it is a crowd-sourcing dApp or a crypto wallet, you have to define various functions for it. Then you’ll need a reliable Ethereum API for your project. These APIs interact with blockchain nodes for sending and receiving transactions and authenticating users. After you’re finished with the coding headache, you need to find reliable RPC providers. However, with Moralis, you don’t need to worry about any of that. Moralis will do all of them on your behalf.

Ethereum Send Transaction – How to Transfer Tokens with Moralis?

Perhaps you are making a tracking app that monitors your transactions. Or a “crypto kitty” app that allows your users to buy and sell virtual pets. Whatever the case might be, your dApps need to interact with Ethereum. If you have used the Web3.js library for your node.js projects, you will admit that it is cumbersome. To use Web3.js for transferring tokens and sending NFT transactions, you need to construct the whole data structure. In addition, you must have a solid understanding of ABIs. Just as a reminder, an ABI (application binary interface) is an interface that facilitates communications between programs. But do not panic if you’re not 100% sure on how to utilize an ABI; Moralis’ Web3 platform has made it easy for you. Thanks to its backend development infrastructure, you can initiate Ethereum send transaction functionality with just one line of code.

To move native assets on a given blockchain using Moralis, you first need to make an “option” object. Set its “type” value as “native” so that Moralis will understand that you want to transfer native assets. The reason is that for transferring cross-chain assets, you need to implement other procedures. In the next stage, you have to specify the amount of value for the transfer. Regardless of which blockchain you’re using (Ethereum, Polygon, Binance Smart Chain, etc.), use the “Moralis.units.ETH” command. Since every transaction has a sender and receiver, now it is time to specify the “receiver”. Enter your intended wallet address as below, and that is it.

 // sending 0.5 ETH
 const options = {type: "native", amount: Moralis.Units.ETH("0.5"), receiver: "0x.."}
 let result = await Moralis.transfer(options)

Transferring ERC-20 Tokens

To send ERC-20 tokens using the Moralis platform, you need the token’s contract address and the number of decimals. Check your account on Etherscan or any other block explorer that you use for your project to find this data. To initiate Moralis transactions, you have to use the helper function: “Moralis.Units.Token”. It lets you multiply the amount of value by the number of decimals. Getting your tokens’ metadata is also possible without referring to your block explorer. Moralis’ SDK has a solution for this purpose. Just check our documentation about getting tokens’ metadata.

 // sending 0.5 tokens with 18 decimals
 const options ={type: "erc20",
             	amount: Moralis.units.Token("0.5", "18"),
             	Receiver: "0x..",
             	contractAddress: "0x.."}
 let result = await Moralis.transfer(options)

Transferring ERC-721 Tokens 

For transferring these types of tokens, you’ll need the “contractAddress” of the NFT as well as “tokenID”. Here you do not need to specify the “amount” because you can only transfer one token at a time.

 // sending a token with token id = 1
 const options = {type: "erc721",
              	receiver: "0x..",
              	contractAddress: "0x..",
              	tokenId: 1}
 let result = await Moralis.transfer(options)

Transferring ERC-1155 Tokens

To transfer these tokens, also known as semi-fungibles, you have to specify the “contactAddress” and “tokenID” of the NFT. You should also determine the “amount” of tokens to transfer.

 // sending 15 tokens with token id = 1
 const options = {type: "erc1155",
             	   receiver: "0x..",
            	   contractAddress: "0x..",
              	   tokenId: 1,
 let result= await Moralis. transfer(options)

Callbacks Promises Events

Every Ethereum transaction happens through multiple stages. Whenever each step is completed, the blockchain returns a “promise” and will then begin the next phase. The implicit functionality within the blockchain is called the “asynchronous” function. Moralis’ infrastructure has provided the opportunity for developers to obtain information about each stage of the transaction. For this purpose, you only need to use the “Moralis.transfer()” function, which supports the “promise event”.

Thanks to this capability, you can now get “transactionHash” before completing the process, which essentially is a transaction ID. Using the command “receipt”, you can get the receipt of your transaction after completing its processing. By changing “awaitReceipt” to “false” in the transaction option section, you will receive all data as event callbacks. 

 const txOptions = {
  type: "erc20",
  amount: Moralis.Units.Token("10","18"),
  receiver:   "0xB5…ee035",
  contractAddress: ("0x7b…605e",
  awaitReceipt: false // should be switched to false

 const tx = await Moralis.transfer (txOptions);

 tx.on("transactionHash", (hash) => {…})
   .on ("receipt", (receipt) => {…})
   .on ("confirmation", (confirnationNumber, receipt) => { ... })
   .on ("error", (error) => {…})

Ethereum Gas Fees

Ethereum is not an entirely free network, and you should pay for sending your transactions and executing your smart contracts. You may have heard of “gas fees” in the crypto world but never read about it. In the blockchain world, “gas fee” refers to the cost of processing transactions on the blockchain. Whether you are buying tokens or sending transactions, you must pay its cost in ETH. There is a general rule for calculating the gas fee; the more complex your transaction is on Ethereum, the higher your gas fee. 

Then there is the “gas limit”, which is the maximum amount of gas fee you can pay for each transaction. To calculate the gas fee, you should multiply the gas limit by the gas price. The gas price is based on how fast you want your calculations (gas limit x gas price = gas fee). Gas fees are also payable in “Gwei”, which is equal to 1^ -8 ETH (or .000000001 eth). If you want to mint NFTs without paying gas, so-called we’ve got an article on how to lazy mint NFTs on the Moralis blog.

Ethereum API Mixed with Moralis

Every decentralized application should have some primary capabilities, including but not limited to user authentication, reading databases, and sending assets. Whether building an NFT marketplace or a DeFi dashboard, you’ll need to incorporate these features into your dApps. The Ethereum API and Moralis’ infrastructure lets you add all of the capabilities mentioned above to your dApps with short snippets of code. The API is fully integrated with the MetaMask authentication solution and WalletConnect (for mobile users). It also eliminates your need for blockchain RPC node providers since all of your dApps will run on Moralis Speedy Nodes. Integrated with all of Moralis’ services, Moralis Speedy Nodes come with exceptional speed and are easily scalable. 

Summary – Ethereum Send Transaction Basics – Send Ethereum with One Line of Code

Developers hardly dare to make blockchain applications. The problem is that you need to have extensive knowledge about APIs, ABIs, data structures, RPC nodes, etc. In addition, you have to possess solid coding skills. However, thanks to Moralis’ backend development infrastructure, blockchain development feels like a breeze and is no longer rocket science. Using its tools, you can initiate Ethereum send transaction functionality with just one line of code. Moralis also lets you integrate Ethereum API capabilities, including user authentication and sending NFTs into your dApps. Furthermore, you’ve learned about different token standards and how the functionality of sending Ehtereum transactions actually works. We’ve also looked at various code examples that will help you throughout the development process.

If you aspire to become a blockchain developer, make sure to check out Moralis Academy today! At Moralis Academy, we teach you everything from blockchain basics to advanced Ethereum smart contract programming. As such, you can let Moralis guide you from start to finish and, in turn, future-proof your blockchain career!

Moralis Money
Stay ahead of the markets with real-time, on-chain data insights. Inform your trades with true market alpha!
Moralis Money
Related Articles
November 22, 2023

Best NFT Data Analytics for 2024 – Real-Time NFT Transfers, Tracking & Discovery

September 29, 2022

How to Connect PlayFab with Web3 Using Azure Functions

September 20, 2022

Solana NFT Mint Tools – Create Your Own Solana NFT

March 20, 2023

How to Get an Address’ Token Balance on Solana

December 29, 2022

Web3 Wallet Tracker – How to Create a Firebase Web3 Wallet Tracker

January 24, 2023

Solana Python API – How to Use the Solana API in Python

March 3, 2023

Optimism Goerli Faucet – How to Get Free Optimism Testnet Funds

December 14, 2023

Holesky Faucet – How to Get Free Holesky Testnet Funds