SMART CONTRACTS
WHAT IS A SMART CONTRACT?
A "smart contract" is simply a program that runs on the BTC20 Smart Chain blockchain. It's a collection of code (its functions) and data (its state) that resides at a specific address on the BTC20 Smart Chain blockchain.
Smart contracts are a type of BTC20 Smart Chain account. This means they have a balance and can be the target of transactions. However they're not controlled by a user, instead they are deployed to the network and run as programmed. User accounts can then interact with a smart contract by submitting transactions that execute a function defined on the smart contract. Smart contracts can define rules, like a regular contract, and automatically enforce them via the code. Smart contracts cannot be deleted by default, and interactions with them are irreversible.
A DIGITAL VENDING MACHINE
To get a snack from a vending machine:
This logic is programmed into the vending machine.
A smart contract, like a vending machine, has logic programmed into it. Here's a simple example of how this vending machine would look if it were a smart contract written in Solidity:
Like how a vending machine removes the need for a vendor employee, smart contracts can replace intermediaries in many industries.
PERMISSIONLESS
Anyone can write a smart contract and deploy it to the network. You just need to learn how to code in a smart contract language, and have enough BTCC to deploy your contract. Deploying a smart contract is technically a transaction, so you need to pay gas in the same way you need to pay gas for a simple BTCC transfer. However, gas costs for contract deployment are far higher.
BTC20 Smart Chain has developer-friendly languages for writing smart contracts:
Solidity
However, they must be compiled before they can be deployed so that EVM can interpret and store the contract.
COMPOSABILITY
Smart contracts are public on BTC20 Smart Chain and can be thought of as open APIs. This means you can call other smart contracts in your own smart contract to greatly extend what's possible. Contracts can even deploy other contracts.
LIMITATIONS
Smart contracts alone cannot get information about "real-world" events because they can't retrieve data from off-chain sources. This means they can't respond to events in the real world. This is by design. Relying on external information could jeopardise consensus, which is important for security and decentralization.
However, it is important for blockchain applications to be able to use off-chain data. The solution is oracles which are tools that ingest off-chain data and make it available to smart contracts.
Another limitation of smart contracts is the maximum contract size. A smart contract can be a maximum of 24KB or it will run out of gas.
MULTISIG CONTRACTS
Multisig (multiple-signature) contracts are smart contract accounts that require multiple valid signatures to execute a transaction. This is very useful for avoiding single points of failure for contracts holding substantial amounts of btcc or other tokens. Multisigs also divide responsibility for contract execution and key management between multiple parties and prevent the loss of a single private key leading to irreversible loss of funds. For these reasons, multisig contracts can be used for simple DAO governance. Multisigs require N signatures out of M possible acceptable signatures (where N ≤ M, and M > 1) in order to execute. N = 3, M = 5
and N = 4, M = 7
are commonly used. A 4/7 multisig requires four out of seven possible valid signatures. This means the funds are still retrievable even if three signatures are lost. In this case, it also means that the majority of key-holders must agree and sign in order for the contract to execute.
Last updated