0
0
Blockchain / Solidityprogramming~5 mins

Why DeFi reimagines finance in Blockchain / Solidity

Choose your learning style9 modes available
Introduction

DeFi changes how money works by using computers to do banking without banks. It makes finance open and fair for everyone.

When you want to send money to someone without a bank in the middle.
When you want to borrow or lend money without filling out lots of forms.
When you want to trade or invest without paying big fees.
When you want to keep control of your money without trusting a company.
When you want to use money apps that work 24/7 without closing.
Syntax
Blockchain / Solidity
DeFi uses smart contracts on blockchains like Ethereum.

Example smart contract function:
function transfer(address to, uint amount) public {
  require(balance[msg.sender] >= amount);
  balance[msg.sender] -= amount;
  balance[to] += amount;
}

Smart contracts are like computer programs that run on the blockchain automatically.

They make sure rules are followed without needing a bank or middleman.

Examples
This function lets users add money to their account in the contract.
Blockchain / Solidity
function deposit() public payable {
  balance[msg.sender] += msg.value;
}
This function lets users borrow money if they have enough collateral.
Blockchain / Solidity
function borrow(uint amount) public {
  require(collateral[msg.sender] >= amount);
  loans[msg.sender] += amount;
  balance[msg.sender] += amount;
}
Sample Program

This simple DeFi contract lets users deposit money and send it to others without a bank.

Blockchain / Solidity
pragma solidity ^0.8.0;

contract SimpleDeFi {
    mapping(address => uint) public balance;

    function deposit() public payable {
        balance[msg.sender] += msg.value;
    }

    function transfer(address to, uint amount) public {
        require(balance[msg.sender] >= amount, "Not enough balance");
        balance[msg.sender] -= amount;
        balance[to] += amount;
    }
}
OutputSuccess
Important Notes

DeFi uses code to replace banks and middlemen.

It works on blockchains, which are like shared computers everyone trusts.

Smart contracts run automatically and cannot be changed once live.

Summary

DeFi makes finance open and automatic using smart contracts.

It removes banks and lets people control their own money.

DeFi works 24/7 and is available to anyone with internet.