Solidity language, contract anatomy, libraries, and composability.
This guide covers the fundamentals of smart contracts on MAPO-Relay-Chain, including the Solidity language, contract structure, libraries, and composability.
Solidity Language
MAPO smart contracts primarily use Solidity as the programming language.
Object-oriented, high-level language for implementing smart contracts
Curly-bracket syntax influenced by C++
Statically typed (variable types known at compile time)
Supports inheritance, libraries, and complex user-defined types
Smart contracts are public and can be thought of as open APIs. You can use existing contracts as building blocks for your project.
Principles
Modularity - Each contract performs a specific task
Autonomy - Contracts operate independently and are self-executing
Discoverability - Contracts are open-source and publicly available
Benefits
Shorter development cycle - Reuse existing solutions
Greater innovation - Focus on new features instead of basic functionality
Better user experience - Interoperability between dapps
Example: Flash Loans
Flash loans demonstrate composability - borrowing assets without collateral, using them across multiple protocols, and repaying within one transaction. This requires combining calls to multiple contracts.
contract SimpleStorage {
uint storedData; // State variable
}
// View function - doesn't modify state
function balanceOf(address _owner) public view returns (uint256) {
return ownerBalance[_owner];
}
// State-changing function
function update_name(string value) public {
dapp_name = value;
}