Introduction

Smart Contract

A "smart contract" serves as an application program operating within the POX network. Comprising a set of code (housing its functions) and data (representing its state), it resides at a specific account address on the POX network. Smart contracts, akin to a distinctive category of POX accounts, possess a balance and the ability to initiate transactions across the network. Unlike user-controlled accounts, these contracts operate independently; upon deployment to the network, they execute as programmed without user intervention. Users can engage with a smart contract by initiating transactions that execute predefined functions within the contract, yet these interactions are irreversible.

Perhaps the best metaphor for a smart contract is a vending machine. With the right inputs, a certain output is guaranteed. This logic is programmed into the vending machine: currency + snack selection = snack dispensed. Users can obtain a snack from a Pollux-based vending machine.

A smart contract, akin to a vending machine, encapsulates programmed logic within its structure. Let's explore a straightforward illustration of a smart contract, resembling the functionality of a vending machine:

Solidity=
pragma solidity 0.8.7;

contract VendingMachine {

    // Declare state variables of the contract
    address public owner;
    mapping (address => uint) public cupcakeBalances;

    // When 'VendingMachine' contract is deployed:
    // 1. set the deploying address as the owner of the contract
    // 2. set the deployed smart contract's cupcake balance to 100
    constructor() {
        owner = msg.sender;
        cupcakeBalances[address(this)] = 100;
    }

    // Allow the owner to increase the smart contract's cupcake balance
    function refill(uint amount) public {
        require(msg.sender == owner, "Only the owner can refill.");
        cupcakeBalances[address(this)] += amount;
    }

    // Allow anyone to purchase cupcakes
    function purchase(uint amount) public payable {
        require(msg.value >= amount * 1 trx , "You must pay at least 1 TRX per cupcake");
        require(cupcakeBalances[address(this)] >= amount, "Not enough cupcakes in stock to complete this purchase");
        cupcakeBalances[address(this)] -= amount;
        cupcakeBalances[msg.sender] += amount;
    }
}

Similar to how a vending machine eliminates the necessity for a vendor employee, intelligent contracts have the potential to substitute intermediaries across various industries.

Properties Of Smart Contracts

Smart contracts in Pollux network have the following properties:

  • Permissionless: Individuals can create and deploy smart contracts on the Pollux network without requiring explicit permission. Proficiency in a smart contract language is essential, along with a sufficient amount of PRC for the deployment process. Deploying a smart contract is treated as a transaction, necessitating the payment of resource fees, which, in comparison to a basic PRC transfer, are considerably higher.

  • Developer-Friendly Language: Pollux employs Solidity as its developer-friendly language for crafting smart contracts. However, before deployment, these contracts must undergo compilation to enable interpretation and storage by the Pollux Virtual Machine (PVM).

  • Composability: Smart contracts within the Pollux network are public and can be likened to open APIs, allowing seamless integration. This implies that one can invoke other smart contracts within their own, vastly expanding the range of functionalities. Furthermore, contracts have the capability to deploy additional contracts. Aspiring DApp developers don't necessarily need to create their own smart contracts; instead, they can focus on understanding how to interact with existing ones. For instance, leveraging the functionalities of SunSwap, a decentralized exchange, can streamline the token swap logic within an application without starting from square one.

Limitations of Smart Contracts

The Pollux network smart contracts have the following limitations:

  • Unable to communicate with external system: Smart contracts inherently face a challenge in directly interacting with external systems, preventing them from accessing real-world event information. While this constraint limits the application scenarios for smart contracts, it is intentionally designed to uphold consensus, a crucial element for security and decentralization. Addressing this limitation, oracles can be leveraged as a solution to enable smart contracts to obtain external information.

  • Maximum execution time of smart contracts: To ensure optimal network throughput and stable operation, Pollux sets the maximum execution time of the Pollux Virtual Machine (PVM) to 80ms. This configuration guarantees the generation of a new block on the Pollux network every 3 seconds. The permissible execution time for smart contracts is capped at 80ms. Notably, the maximum execution time of PVM stands as the #13 dynamic parameter within the Pollux network. The super representative committee holds the authority to modify this parameter through proposal initiation.

    When complex smart contracts risk exceeding the designated time frame, it may result in a timeout, triggering an OUT_OF_TIME error. The caller is then subject to a deduction from the full fee_limit fee. To mitigate the risk of smart contract execution surpassing the allotted time, it is advisable to decompose extensive contracts into smaller, more manageable ones, referencing each other as necessary. Additionally, developers should remain vigilant regarding common pitfalls and steer clear of recursive calls to prevent inadvertent infinite loops.

Last updated