Smart Contracts Flashcards
Whats is Blockchain
distributed database that maintains a growing list of ordered records called blocks.
How are Blocks linked
Uisng cryptography. Each block contains a hash of the previous block, a timestamp, and transaction data.
Smart Contract
Self-Executing contract with terms directly written into code
Smart Contract (Automation?)
Automatically enforces rules and conditions once pre-defined criteria are met
Key Features (Smart Contract)
(AIDT)
Automation
Immutable: Once deployed, can’t be altered
Decentralised
Transparent and Secure
Smart Contract Workflow
(WDLER)
1: Written
2. Deploy
2: Listen
3: Execute
4: Record
Registry
Record of all deployed contracts, allowing access, and updates
Registry (Contains)
bytecode,
ABI,
developer Docs,
critical information
Registry (Available)
Available at runtime to all participants
Address Book
Used to manage ethereum strings of Hex.
Address Book (How it works)
when a new instance of a user or contract is detected it is added to the book with a link to the contract.
all instances of a contract are listed and a REST API for each is auto-generated.
REST API can be used from any node.
Truffle
Truffle is an automated testing framework to test smart contracts.
Ways to write a test
Javascript and Typescript
Solidity
All files in ./test directory
Truffle will only run .js, .ts, .es, .es6, .jsx, and .sol.
Encryption
The use of a key to encode information so that it cannot be read by nodes without the corresponding decryption key.
Components of smart contract
Pragma directive: solidity compiler version.
Contract Definition: Basic buildign block
State variables: variables
Functions: Blocks of code defining the operations and logic
Modifiers: custom conditions used to modify behaviour of functions
Events: logging mechanisms
Fallback and Receive: Special functions to handle Ether transfers
Data Types: Defines the type of variables
Testing Steps
(WCTDM)
- Writing
- Compiling
- Testing
- Deploying
- Monitoring
Truffle
Development framework for smart contracts.
Simplifies development.
Benefits of Truffle
(ATM)
Automation: automates compiling, deployment, and testing
Testing: Provides testing frameworks (Mocha/Chai)
Migration: Helps manage contract migrations.
Gas
Gas is the unit that measures the computational work required to execute transactions and smart contracts on ethereum.
Gas (How it works)
Each operation costs a certain amount of Gas.
Users pay gas (Ether) to incentivize miners to process transactions.
Gas Limit and price
Limit: the amount of gas a user is willing to spend
Price: the amount a user is willing to pay in ether for each unit of Gas
Artifacts.required()
Helps JavaScript code find and interact with a specific smart contract that you’ve already compiled.