What are Smart Contracts?

A smart contract is a program or protocol based on blockchain technology that automatically executes, verifies, and records contract terms. It runs without human intervention, and once the preset cond

A smart contract is a piece of programmed code deployed on the blockchain to automatically execute contract terms. It can automatically complete specific tasks, such as transferring money, recording transactions, or verifying information, based on preset conditions without the intervention of a third party. The core features of smart contracts are automated execution, transparency, trustworthiness, and immutability.

Simply put, a smart contract is like a "vending machine":

  • You insert a coin (satisfy the conditions)

  • The machine automatically pops up the product (executes the contract)

  • No need for store clerk (intermediary) intervention

Features of Smart Contracts

  • The contract terms are written in code. Once the set conditions are triggered, the contract runs automatically without human intervention.

  • The contract runs on a distributed blockchain network and is not controlled by a central organization.

  • Everyone can view the contract content and execution process.

  • Once deployed to the blockchain, the content of the contract cannot be changed and the records are permanently saved.

  • Automated processes reduce manpower and time costs and avoid cumbersome processes.


How do smart contracts work?

Use a specialized programming language (such as Solidity) to write a smart contract, define the trigger conditions and execution logic.

Publish the contract to the blockchain (such as Ethereum), and each contract has a unique address.

When the preset conditions are met (such as receiving funds or an event occurs), the contract will be automatically executed.

All execution results will be recorded on the blockchain, which is open, transparent, and cannot be tampered with.


Application scenarios of smart contracts

1.Financial services:

  • Decentralized lending: Automatically issuing loans or processing mortgages.

  • Insurance: Automatic claims triggered based on conditions.

  • Payments: Smart contracts ensure that funds are paid on time.

2.Supply Chain:

  • Record the entire process of goods from production to delivery to ensure transparency and traceability.

3.Digital Asset Management:

  • Ensure uniqueness and ownership of assets in NFT and digital collectibles transactions.

4.Voting system:

  • Transparent and secure online voting to prevent fraud.

5.Automatic dividends:

  • According to the profit distribution rules, the smart contract automatically distributes dividends to shareholders.


Advantages and Disadvantages of Smart Contracts

  • No trust required: The execution of the contract depends on the code, not the commitment of both parties.

  • Reduce costs: Eliminate intermediaries, reduce disputes and transaction costs.

  • Transparency and fairness: Contracts and execution records can be publicly reviewed.

  • Global applicability: Blockchain-based smart contracts can be executed across borders.

  • Deployment immutability: cannot be modified after deployment, and execution cannot be backtracked.

  • High technical threshold: requires super professional developers to write and deploy.

  • Blockchain performance limitations: some blockchains (such as Ethereum) have slow transaction processing speeds and high fees.

Example explanation

  • Contract Terms:

  1. On the 1st of each month, if the employee completes the work, a salary of 1,000 USDT will be paid.

  2. If the work is not completed, no salary will be paid.

  • Implementation method:

  1. The company transfers the salary to the smart contract address.

  2. The system checks the employee's work record.

  3. If the conditions are met, the contract will automatically pay wages to the employee's address.

  4. If the conditions are not met, the funds are returned to the company account.


Smart contract example in BitNest

What is BitNestโ€™s smart contract?

The following are several examples of the core functions of the BitNest smart contract:

  1. Automatic distribution of BitNest Loop income

Rules:

Every time an asset provider deposits 100 USDT, the smart contract records the amount and time.

The returns are automatically calculated according to the smart contract rules:

After 1 day: 100.4% return (for example, deposit 100 USDT, 100.4 USDT returned after 1 day).

After 7 days: 104% return.

After 14 days: 109.5% return.

After 28 days: 124% return.

//pragma solidity ^0.8.0;

/**
 * BitNest Loop Smart Contract Example
 * This contract demonstrates how users can deposit funds and earn interest based on the holding period.
 */

contract BitNestLoop {
    address public owner; // Owner of the contract

    struct Deposit {
        uint256 amount; // The deposited amount
        uint256 startTime; // Timestamp when the deposit was made
    }

    mapping(address => Deposit) public deposits; // Tracks deposits for each user

    constructor() {
        owner = msg.sender; // Set the contract owner
    }

    // Deposit funds into the contract
    function deposit() public payable {
        require(msg.value > 0, "Deposit amount must be greater than zero");
        require(deposits[msg.sender].amount == 0, "Existing deposit must be withdrawn first");

        deposits[msg.sender] = Deposit({
            amount: msg.value,
            startTime: block.timestamp
        });
    }

    // Calculate the interest based on the holding period
    function calculateInterest(address user) public view returns (uint256) {
        Deposit memory userDeposit = deposits[user];
        require(userDeposit.amount > 0, "No active deposit found");

        uint256 holdingPeriod = block.timestamp - userDeposit.startTime; // Calculate holding period in seconds
        uint256 interestRate;

        // Determine the interest rate based on the holding period
        if (holdingPeriod >= 28 days) {
            interestRate = 240; // 24% interest
        } else if (holdingPeriod >= 14 days) {
            interestRate = 95; // 9.5% interest
        } else if (holdingPeriod >= 7 days) {
            interestRate = 40; // 4% interest
        } else if (holdingPeriod >= 1 days) {
            interestRate = 4; // 0.4% interest
        } else {
            interestRate = 0; // No interest for less than 1 day
        }

        return (userDeposit.amount * interestRate) / 1000; // Return calculated interest
    }

    // Withdraw deposited funds along with the earned interest
    function withdraw() public {
        Deposit memory userDeposit = deposits[msg.sender];
        require(userDeposit.amount > 0, "No deposit to withdraw");

        uint256 interest = calculateInterest(msg.sender); // Calculate the interest
        uint256 totalAmount = userDeposit.amount + interest; // Add interest to the principal amount

        // Reset the user's deposit
        delete deposits[msg.sender];

        // Transfer funds to the user
        payable(msg.sender).transfer(totalAmount);
    }

    // Check the deposit details of a user
    function getDepositDetails(address user) public view returns (uint256 amount, uint256 startTime) {
        Deposit memory userDeposit = deposits[user];
        return (userDeposit.amount, userDeposit.startTime);
    }
}
  1. Invitation Rewards

Rules:

For each new user invited and enabled to provide liquidity, the inviter can receive multiple levels of rewards.

Reward structure:

Direct invitation (level 1): 20% profit.

Indirect invitation (level 2): โ€‹โ€‹10% profit.

Levels 3-7: 5% profit.

Levels 8-10: gradually reduced to 3%.

Levels 11-17: gradually reduced to 1%.


Last updated