New Ethereum talks, every Monday. The week's conference uploads by event, in your inbox.

Loading player…

Anatomy of a Smart Contract

BaseMon, Oct 9, 2023, 12:00 AM

Ever wondered how smart contracts work on the blockchain? This video breaks it down, showing you their simplicity and how they power NFT projects. Learn about functions, data storage, and the benefits of Ethereum's smart contracts. It's easier than you think! 📚 Head to Base Camp for full courses on smart contract development: https://docs.base.org/base-camp/docs/welcome ✅ Subscribe to our channel here: https://www.youtube.com/@BuildonBase ► Build on Base: https://base.org ► Follow us on Twitter: https://twitter.com/buildonbase ► Join our Discord: https://base.org/discord

Transcript

foreign contracts sound complicated but they're actually quite simple a smart contract is merely a collection of code that lives on blockchain which users can interact with in predetermined ways this code defines rules like any other contract and since smart contracts are immutable these rules cannot be changed and are therefore automatically enforced to go deeper in understanding smart contracts let's examine the anatomy of a real world smart contract we'll do this by imagining we're launching a new nft project which will require a smart contract that can mint our nfts like all smart contracts the anatomy of our nft smart contract will be made up of functions how our contract makes decisions and execute transactions and data the state of our contract let's start by looking at the functions in our nft smart contract first we'd have some Constructor logic which is executed when the contract is created in our case this logic would Define a few basic properties of our nft such as the mint price total Supply Mac Supply and Max per wallet next we'd write a handful of other functions such as a mint function which actually mints rnfts the code inside these functions will take some of our other variables into account such as mint price total Supply Max per wall Etc to ensure that users are not minting too many nfts paying too little for them or doing anything else outside of the balance of what our contract should allow next let's look at the data or state of our smart contract in the case of our nft contract we need some place to store State variables such as our mint price total Supply Etc the obvious solution is to persist this information permanently on the blockchain lastly it should be noted that ethereum smart contracts are one of two types of ethereum accounts in addition to contract accounts the other type of account is an externally owned account or eoa eoas can initiate transactions and are made up of a cryptographic pair of public and private Keys which control the accounts activities these are the types of accounts that users associate with their wallets contract accounts cannot initiate transactions but can only send transactions in response to receiving a transaction and unlike eoa accounts contract accounts do not have private keys they are controlled by the smart contract code not key holders two properties that both eoa and contract accounts have is one nonce which is a counter to keep track of the number of transactions for the account and the balance this is how much ethi account owns denoted in way a denomination of eth hopefully you can see that though ethereum smart contracts harness powerful principles of decentralization they're actually not as complex as you might think

Automatic transcript — names and jargon may be misspelled.