A standard on Github labels for contribution
How to make your need for external contribution explicit and widely visible?At Only Dust we believe than in a close future most developers will get paid in crypto to contribute to open source projects, not as employees but as contributors.To help it happen there is a lot to do: create communities, involve companies, create some kind of on-chain platform for missions to be posted on. That’s a lot to do, too much for one sprint or even one year. So we decided to start small, to find quick wins ...
Demystifying StarkNet accounts
IntroductionWhen trying StarkNet for the first time, it’s easy to go through the account setup without paying much attention to it. The documentation just says:Unlike Ethereum, which distinguishes between Externally Owned Accounts (EOA) and contracts, StarkNet doesn’t have this distinction. Instead, an account is represented by a deployed contract that defines the account’s logic — most notably the signature scheme that controls who can issue transactions from it.Then, you are invited to chos...
protostar vs nile
When starting a new project in a new programming language, there is always this question that is raised.Which framework should I choose ?For Starknet projects, there are especially 2 new frameworks I have been trying and would like to compare: protostar and nile. I have detailed the comparison in this github repository. Several aspects are treated:InstallationProject initializationCompilationUnit testingAssertionsMockingDebuggingDeploymentPerformancesAnd the winner is…For the more impatient o...
We onboard devs to the Starknet ecosystem. Our discord : https://discord.gg/onlydust To create Stars, you need Only Dust.
A standard on Github labels for contribution
How to make your need for external contribution explicit and widely visible?At Only Dust we believe than in a close future most developers will get paid in crypto to contribute to open source projects, not as employees but as contributors.To help it happen there is a lot to do: create communities, involve companies, create some kind of on-chain platform for missions to be posted on. That’s a lot to do, too much for one sprint or even one year. So we decided to start small, to find quick wins ...
Demystifying StarkNet accounts
IntroductionWhen trying StarkNet for the first time, it’s easy to go through the account setup without paying much attention to it. The documentation just says:Unlike Ethereum, which distinguishes between Externally Owned Accounts (EOA) and contracts, StarkNet doesn’t have this distinction. Instead, an account is represented by a deployed contract that defines the account’s logic — most notably the signature scheme that controls who can issue transactions from it.Then, you are invited to chos...
protostar vs nile
When starting a new project in a new programming language, there is always this question that is raised.Which framework should I choose ?For Starknet projects, there are especially 2 new frameworks I have been trying and would like to compare: protostar and nile. I have detailed the comparison in this github repository. Several aspects are treated:InstallationProject initializationCompilationUnit testingAssertionsMockingDebuggingDeploymentPerformancesAnd the winner is…For the more impatient o...
We onboard devs to the Starknet ecosystem. Our discord : https://discord.gg/onlydust To create Stars, you need Only Dust.
Share Dialog
Share Dialog
Subscribe to Only Dust
Subscribe to Only Dust
<100 subscribers
<100 subscribers
When I learn a new language, my first focus is to build SOLID components while leveraging the feature of this new language.
In this article, I would like to present a new convention we at OnlyDust are adopting with regards to cairo development.
This new kind of architecture feels like object-oriented programming in a way and leverage several cairo features like:
implicit parameters
structs
namespaces
Following OpenZeppelin’s recommendations about extensibility, we aims at building nice modules that can be re-usable and well tested.
A module is composed of:
structs to represent the current state of an object
external functions that are aimed at being imported (in smart contracts and unit tests)
internal functions that are meant to be kept private
As the memory is immutable in cairo, when interacting with an object, this object is usually being copied into a new version to be used. Using explicit parameters, this would result in providing the object both as input parameter and output parameter. Implicit parameters are better suited for this need as this is automatically done by the language.
This convention is especially useful when dealing with in-memory object when usage of storage is to be limited.
Let’s see how it looks:
# person.cairo
%lang starknet
from starkware.cairo.common.math import assert_nn, assert_not_zero
struct Wallet:
member token : felt
member balance : felt
end
# External functions
namespace wallet_access:
func create(token : felt) -> (wallet : Wallet):
let wallet = Wallet(token, 0)
internal.check_wallet{wallet=wallet}()
return (wallet=wallet)
end
func increase_balance{wallet : Wallet}(amount : felt):
let wallet = Wallet(wallet.token, wallet.balance + amount)
return ()
end
end
# Internal functions
namespace internal:
func check_wallet{wallet : Wallet}():
with_attr error_message("Token cannot be 0"):
assert_not_zero(wallet.token)
end
return ()
end
end
And here is the contract file that interact with it:
# dex.cairo
%lang starknet
from src.wallet import Wallet, wallet_access
@external
func do_something(wallet : Wallet) -> (wallet : Wallet):
with wallet:
wallet_access.increase_balance(42)
# Here wallet has been updated
end
return (wallet=wallet)
end
Using this convention, it is actually possible to build SOLID modules and interact with them.
It allows to build some design patterns on top of it like the iterator pattern presented here.
When I learn a new language, my first focus is to build SOLID components while leveraging the feature of this new language.
In this article, I would like to present a new convention we at OnlyDust are adopting with regards to cairo development.
This new kind of architecture feels like object-oriented programming in a way and leverage several cairo features like:
implicit parameters
structs
namespaces
Following OpenZeppelin’s recommendations about extensibility, we aims at building nice modules that can be re-usable and well tested.
A module is composed of:
structs to represent the current state of an object
external functions that are aimed at being imported (in smart contracts and unit tests)
internal functions that are meant to be kept private
As the memory is immutable in cairo, when interacting with an object, this object is usually being copied into a new version to be used. Using explicit parameters, this would result in providing the object both as input parameter and output parameter. Implicit parameters are better suited for this need as this is automatically done by the language.
This convention is especially useful when dealing with in-memory object when usage of storage is to be limited.
Let’s see how it looks:
# person.cairo
%lang starknet
from starkware.cairo.common.math import assert_nn, assert_not_zero
struct Wallet:
member token : felt
member balance : felt
end
# External functions
namespace wallet_access:
func create(token : felt) -> (wallet : Wallet):
let wallet = Wallet(token, 0)
internal.check_wallet{wallet=wallet}()
return (wallet=wallet)
end
func increase_balance{wallet : Wallet}(amount : felt):
let wallet = Wallet(wallet.token, wallet.balance + amount)
return ()
end
end
# Internal functions
namespace internal:
func check_wallet{wallet : Wallet}():
with_attr error_message("Token cannot be 0"):
assert_not_zero(wallet.token)
end
return ()
end
end
And here is the contract file that interact with it:
# dex.cairo
%lang starknet
from src.wallet import Wallet, wallet_access
@external
func do_something(wallet : Wallet) -> (wallet : Wallet):
with wallet:
wallet_access.increase_balance(42)
# Here wallet has been updated
end
return (wallet=wallet)
end
Using this convention, it is actually possible to build SOLID modules and interact with them.
It allows to build some design patterns on top of it like the iterator pattern presented here.
No activity yet