<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Harsh Bansal</title>
    <description>The latest articles on Forem by Harsh Bansal (@harshbansal47).</description>
    <link>https://forem.com/harshbansal47</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1165753%2Fc5c1ec07-2fd4-4658-b882-a06488cee46e.png</url>
      <title>Forem: Harsh Bansal</title>
      <link>https://forem.com/harshbansal47</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/harshbansal47"/>
    <language>en</language>
    <item>
      <title>Smart Contract working in etherium with Metamask wallet</title>
      <dc:creator>Harsh Bansal</dc:creator>
      <pubDate>Thu, 01 Jan 2026 22:31:43 +0000</pubDate>
      <link>https://forem.com/harshbansal47/understanding-smart-contract-in-etherium-and-solidity-1o01</link>
      <guid>https://forem.com/harshbansal47/understanding-smart-contract-in-etherium-and-solidity-1o01</guid>
      <description>&lt;p&gt;Solidity is a programming language designed for writing smart contracts on the Ethereum blockchain. Smart contracts are self-executing programs that contain a predefined set of rules, conditions, and functions. Once deployed to the blockchain, they run automatically when specific conditions are met—without the need for intermediaries.&lt;/p&gt;

&lt;p&gt;Smart contracts run on the Ethereum Virtual Machine (EVM), a decentralized runtime environment that ensures the same code executes identically on every Ethereum node. These contracts handle transactions, store data, and interact with other contracts based on their programmed logic.&lt;/p&gt;

&lt;p&gt;How Are Smart Contracts Triggered?&lt;/p&gt;

&lt;p&gt;Smart contracts do not run automatically on their own. They execute only when triggered by a transaction.&lt;/p&gt;

&lt;p&gt;A smart contract is triggered when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A user sends a transaction&lt;/li&gt;
&lt;li&gt;Another smart contract calls it&lt;/li&gt;
&lt;li&gt;An external application (dApp backend, script, or bot) interacts with it
In all cases, execution starts with a transaction sent to the contract address.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example: Triggering a Smart Contract Using MetaMask&lt;br&gt;
Let’s say a user wants to perform a transaction using the MetaMask wallet.&lt;/p&gt;

&lt;p&gt;The user initiates a transaction in MetaMask&lt;br&gt;
Instead of sending ETH to a regular wallet address, the user enters a smart contract address&lt;/p&gt;

&lt;p&gt;Behind the scenes, MetaMask prepares the transaction with the following details:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Contract address – Which smart contract to call&lt;/li&gt;
&lt;li&gt;Function selector – Which function to execute&lt;/li&gt;
&lt;li&gt;Parameters – Input values required by the function&lt;/li&gt;
&lt;li&gt;Gas limit &amp;amp; gas price – How much the user is willing to pay for execution&lt;/li&gt;
&lt;li&gt;Value (optional) – Amount of ETH (or native coin) to send&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Transaction Creation and Signing&lt;br&gt;
Once the transaction details are set:&lt;br&gt;
MetaMask creates a transaction object&lt;br&gt;
The transaction is signed using the user’s private key&lt;br&gt;
This cryptographic signature proves that the user authorized the action&lt;br&gt;
⚠️ The private key never leaves the wallet&lt;br&gt;
Broadcasting the Transaction to the Network&lt;/p&gt;

&lt;p&gt;After signing:&lt;br&gt;
The wallet sends the transaction to the Ethereum network&lt;br&gt;
Nodes receive it and propagate it across the network&lt;br&gt;
The transaction enters the mempool (a pool of pending transactions)&lt;/p&gt;

&lt;p&gt;Block Validation and Execution&lt;br&gt;
Depending on the consensus mechanism:&lt;br&gt;
Miners (Proof of Work – older Ethereum)&lt;br&gt;
Validators (Proof of Stake – current Ethereum)&lt;/p&gt;

&lt;p&gt;They:&lt;br&gt;
Select pending transactions&lt;br&gt;
Execute them locally to verify validity&lt;br&gt;
Bundle them into a block&lt;br&gt;
Add the block to the blockchain&lt;/p&gt;

&lt;p&gt;What Happens Inside the EVM?&lt;br&gt;
When a node processes your transaction, the Ethereum Virtual Machine performs the following steps:&lt;br&gt;
Decode the transaction data&lt;br&gt;
Extracts the function signature and parameters&lt;/p&gt;

&lt;p&gt;Locate the contract code&lt;br&gt;
Uses the contract address to fetch bytecode from the blockchain&lt;br&gt;
Match the function&lt;br&gt;
Identifies the correct function using the function selector&lt;/p&gt;

&lt;p&gt;Execute the function logic&lt;br&gt;
Runs the Solidity code instruction by instruction&lt;/p&gt;

&lt;p&gt;Check conditions&lt;br&gt;
For example:&lt;br&gt;
Does the user have enough balance?&lt;br&gt;
Is the caller authorized?&lt;br&gt;
Update blockchain state&lt;br&gt;
Transfer tokens&lt;br&gt;
Modify stored values&lt;br&gt;
Emit events&lt;/p&gt;

&lt;p&gt;If any check fails (e.g., insufficient balance or failed require condition), the transaction reverts, and state changes are discarded (though gas is still spent).&lt;/p&gt;

&lt;p&gt;Token Standards and Protocols&lt;br&gt;
Smart contracts often follow predefined standards, depending on the blockchain and ecosystem:&lt;br&gt;
ERC-20 – Ethereum token standard&lt;br&gt;
BEP-20 – Binance Smart Chain token standard&lt;br&gt;
TRC-20 – TRON token standard&lt;/p&gt;

&lt;p&gt;These standards define how functions like transfer, approve, and balanceOf behave, ensuring compatibility across wallets and dApps.&lt;/p&gt;

&lt;p&gt;Summary&lt;br&gt;
In short:&lt;br&gt;
Smart contracts execute only when triggered by a transaction&lt;br&gt;
Wallets like MetaMask prepare and sign transactions&lt;br&gt;
Validators execute contract code inside the EVM&lt;br&gt;
Execution follows strict rules and consumes gas&lt;br&gt;
The result is permanently recorded on the blockchain&lt;/p&gt;

</description>
      <category>solidity</category>
      <category>ethereum</category>
      <category>smartcontract</category>
      <category>web3</category>
    </item>
  </channel>
</rss>
