Note: The resource above offers an in-depth explanation on the information summarized below.
Introduction
Solidity is a popular language used to write smart contracts, programs that contain a set of rules which run on the blockchain to execute transactions. It’s similar to JavaScript, so those familiar with JS can easily grasp Solidity’s syntax.
Solidity’s Compilation of Smart Contracts
The compilation of a smart contract is crucial as it provides a JSON interface which describes the smart contract’s information, including the interface that contains all the methods that can be used to interact with the smart contract, such as public and external methods.
Introduction to Remix
Remix provides pre-written smart contract templates to help beginners get started. When you start Remix, it provides a default workspace with three pre-written contracts. You can deploy these smart contracts using the Remix environment or you can use other providers.
Solidity’s Data Types
Solidity uses several data types including integers, unsigned integers, address, enums, arrays and mappings.
- Integers and Unsigned Integers: Integers can have negative and positive values while unsigned integers can only have positive values.
- Address: This represents a 20 byte value, which is the size of an Ethereum address.
- Enums: Used to create custom types with a finite set of ‘enum literals’.
- Arrays: Solidity provides both static (fixed size) and dynamic arrays.
- Mappings: This is an associative array where you define a key type and a value type.
Solidity Function Visibility
In Solidity, function visibility is divided into four types - public
, private
, internal
and external
.
- Public functions: These can be called both inside and outside the contract.
- Private functions: Can only be called from within the contract where they are defined.
- Internal functions: Like private functions, these can only be called from inside the contract itself, as well as contracts deriving from it.
- External functions: These are part of the contract interface, which means they can be called from other contracts and transactions, but not from within the contract.
Basic Smart Contract
A basic contract can be written where an owner can whitelist an address to perform a certain operation. Once the contract is compiled, it can be deployed to a local version of the EVM (Ethereum Virtual Machine) for testing.
Solidity’s Memory and Storage
There are two places where you can store variables in Solidity - memory and storage.
- Storage: This is where all the contract state variables reside. Every contract has permanent storage that persists between function calls and transactions.
- Memory: This is a temporary place to store data. Memory is erased between external function calls and is cheaper to use than storage.
In Summary
Solidity and Remix offer a great platform to start learning about smart contracts. While diving into Solidity, you’ll come across different data types, function visibilities, and storage types. Always remember to test your smart contracts extensively, ensure the contracts are secure, and aim for gas optimization.
For deeper knowledge about EVM internals and security resources, refer to this link. If you have queries, reach out to the workshop presenter, Viraz, on Twitter (@viraj04) or through the Build Cello Hackathon Discord server. Introduction
Solidity is a popular language used to write smart contracts, programs that contain a set of rules which run on the blockchain to execute transactions. It’s similar to JavaScript, so those familiar with JS can easily grasp Solidity’s syntax.