Smart contracts are executed on blockchain, which means that the terms are stored in a distributed database and cannot be changed.
Just like we can add any data into a block, we can add software programs into a block.
🕵️♀️ Definition: These software programs that go into the blocks are called “smart contracts.”
Users can trigger the existing code pieces (“smart contracts”) on a blockchain to execute them with the inputs they want.
Every smart contract is associated with an account. Users also have accounts. When a user wants to trigger (“call”) a smart contract, that user creates a transaction to the smart contract account.
🧠 Reminder: New transactions are broadcasted to the node network to be added to the blocks after mining.
Similarly, triggering a smart contract is essentially the same as creating a new transaction to the account of that smart contract. These transactions are broadcasted to the nodes to be included in the next block.
Miners use computational resources, mostly time and memory, to execute smart contracts. To execute this contract, the user pays a "transaction fee" to the miner in exchange for computational resources.
The amount of the transaction fee can vary depending on the complexity of the transaction. A complex smart contract with a large number of transactions consumes more computational resources and therefore requires a higher transaction fee.
Transaction fees help ensure that a blockchain remains decentralized by incentivizing miners to get paid and join the network. Preventing spam and abuse. Charging a fee to run the code prevents spam accounts from sending too many transactions to the network.
💅 Fun fact: Transaction fees are called different things for different blockchains. Aptos, Ethereum and Cosmos use the label "gas fee", while Solana calls it "rent".
As we know from our daily lives, software programs can do many things. But codes in a blockchain have some limitations, as we’ll explain later.
Still, let’s see the two main things that the smart contracts can do when executed:
1️⃣ Generating new transactions to be added to new blocks. A smart contract can create new transactions. These transactions should then be added to the blockchain by miners.
2️⃣ Updating the state of the blockchain. A smart contract can update the state of the blockchain by modifying the data stored on the blockchain. That might mean updating a balance or changing the ownership of an asset.
Decentralized computing systems are complex.
But they come with some advantages that existing computing systems don’t have:
Swap insights and ask questions about “Learn everything about Aptos”.
Ask a question or share your thoughts about this lesson.