I am a beginner learning blockchain development, and I am watching a tutorial on creating a simple dapp that transfers ether to another address, in the tutorial he creates a smart contract called transaction, then he proceeds to make the transaction using ethers.js, then what is the point of creating a contract if I am going to make the transaction using ethers js, and which to choose to use?


pragma solidity ^0.8.9;

contract Transaction{
    event Transfer(address from, address receiver, uint amount, string message, uint256 timestamp, string keyword);
    struct TransferStruct{
        address sender;
        address receiver;
        uint amount;
        string message;
        uint256 timestamp;
        string keyword;

    TransferStruct[] transactions;

    function addToBlockchain(address payable receiver, uint amount, string memory message, string memory keyword ) public{
        transactions.push(TransferStruct(msg.sender, receiver, amount, message, block.timestamp, keyword));
        emit Transfer(msg.sender, receiver, amount, message, block.timestamp, keyword);

    function getAllTransactions() public{

    function getTransactionCount() public view returns(uint256){


1 Answer 1


A Smart Contract is stored on the blockchain and cannot be changed once deployed on it. It can contain rules or logic on how a transaction can be executed. Through it, we can write certain values to the blockchain and read them, for example.

Ethers.js is an example of a JavaScript library that offers us the ability to call functions from a smart contract. In other words, Ethers.js is used to send a transaction to the blockchain network, which can interact with the smart contract.

In short, if you want to define your own logic on how a transaction will be executed, a smart contract is necessary. Then, you can use Ethers.js to communicate with that smart contract by sending transactions and receiving responses.

In most cases, you will need both.

  • Thanks alot for your answer❤️ Mar 18, 2023 at 12:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.