Learning Starknet

Ifeoluwa SanniIfeoluwa Sanni
5 min read

Account abstraction removes the user’s reliance on private keys, making wallets programmable and scalable for users with an improved user experience. Before account abstraction, externally owned accounts were complex to use as users would require installing crypto wallets like Metamask with high transaction fees, and difficulty in setting up. These accounts are also prone to security risks and have limited functionality. Account abstraction brings seamless signup, frictionless swapping, better security and advanced features. Starknet’s native account abstraction simplifies dApp development by allowing developers to focus on building applications without worrying about wallet integrations or account management complexities. This abstraction standardises user interactions, making it easier for developers to create seamless experiences across different applications on the platform. Starknet has implemented this in their wallets, like the Braavos and Argent wallets. Imagine having wallets that you don't have to bug your brain about 12 words, Private keys, high transaction fees and loss of your hard-earned dollars. That is what Starknet did with account abstraction and smart wallet!

Cairo Language

Cairo language has various data types and scalar types. These scalar types include Felt, Booleans(True or False) and Integers. u8: 8-bit, u16: 16-bit,u32: 32-bit, u64: 64-bit, u128: 128-bit, u256: 256-bit and usize: 32-bit are the lists of built-in unsigned integer types in Cairo. Cairo doesn’t have a native string type but offers two ways to handle strings: short strings with single quotes and ByteArray with double quotes.

Building on Starknet

I learnt about the differences between Cairo and Smart Contracts

» Cairo program must always have a main() function, while Smart Contract lacks main()function, but has several entry points

» Cairo can create provable programs outside of Starknet, while Starknet’s smart contracts are exclusively for the Starknet network.

» Cairo programs are run by the Cairo Virtual Machine, while Starknet smart contracts are run by the sequencer

» I also learnt about the Primary function of Functions, which includes the primary way of interacting with a smart contract's state.

» A constructor is a special function that runs once when the contract is deployed. The difference between Public and Private functions.

»Public functions are accessible from outside the contract and must take self as the first argument, while Private functions are accessible only within the contract, and do not require self as the first argument

Building Smart Contracts
The session was focused on the Overview of Scarb, Starkli(Starknet CLI), Starknet Devnet and Katana, Starknet Foundry, Writing and Deploying an ERC20 Contract on Starknet.

» Scarb is the build toolchain and package manager for Cairo and Starknet ecosystems. A few Scarb commands are scarb-h, scarb new, scarb add, scarb build, scarb fmt, scarb test, scarb init, etc.

» Starkli is a command-line tool for interacting with Starknet. It is powered by starknet-rs. Some starkli commands include starkli –vV, starkli block-number --rpc, starkli account, etc.

» Starknet devnet is a local Starknet node, aimed at testing and development. It is just like a real Starknet node, but everything is executed locally. It enables much faster and more private development.

» Starknet is a fast sequencer devnet by the Dojo team that supports local and production deployments. It is a local development with Dojo (a Gaming engine for Starknet).

» Starknet Foundry is the toolchain for developing Starknet smart contracts. It helps with writing, deploying and testing your smart contracts. It is inspired by Foundry.

Building an Advanced Starknet Smart Contract

Cairo components are modular add-ons encapsulating reusable logic, storage and events that can be incorporated into multiple contracts. They are reusable, Interoperable, simple and cooperative.

» Cairo components are very similar to contracts, but unlike smart contracts, they can’t be deployed independently.

» Composability means combining multiple Cairo components to achieve a certain functionality in a contract. Each component in its module is denoted by the #[starknet::component] attribute.

» You define the component interface, which has the function signatures which allow external access to the component logic.

» We also learnt about writing a Token Sale Contract that could Implement a Uniswap V2 style X * Y = K constant product automated market maker, Integrate the ERC20 component, to allow a user to transfer token A to the AMM, swap them for token B and have the AMM send token B back to them, Integrate the Reentrancy Guard component, to ensure the swap function is locked and a user can’t call it again in the middle of a swap.

Testing in Starknet

Testing evaluates a system or its components to determine whether it meets specified requirements or expectations.

Why Testing in Starknet?

» To identify and fix bugs,

» To identify and resolve security vulnerabilities,

» Verification of smart contracts,

» Ensure the correctness and reliability of the smart contract and build your confidence as a developer.
The tool used for testing in Starknet is Starknet Foundry (snforge)

Frontend Integration with Starknet

Starknet.js is a library that connects your Decentralised Application (dApp) to declare and deploy a Contract and deploy a new Account.

» An ABI (Application Binary Interface) is a blueprint that defines how to interact with a smart contract. It specifies the contract functions, parameters they take and how to format data for calls.

» The blockchain-based Starknet network uses JavaScript or TypeScript.

» Starknetkit is a software development kit designed that facilitate the connection with decentralised applications on Starknet.

» Provider API allows you to interact with the Starknet network without signing transactions or messages.

» Signer API allows you to sign transactions and messages, and also allows you to get the public key.

» An Account extends Provider and inherits all of its methods. Accounts can create and verify signatures with a custom signer.

0
Subscribe to my newsletter

Read articles from Ifeoluwa Sanni directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Ifeoluwa Sanni
Ifeoluwa Sanni

I am a Web3 Software developer