NEWTON
Asked
6 months ago
5
views
0
What are the use cases for namespaces? Why would someone use a namespace?
Please give examples
ㅤ This question was originally posted on Triality
0
A main use case for namespaces is to define an interface to your contract that the outside world (other contracts) can call. For example, if in your contract you had the 2 functions increase_balance
and get_balance
, you could then create a namespace with the function names (omit the bodies):
@contract_interface
namespace IBalanceContract:
func increase_balance(amount : felt):
end
func get_balance() -> (res : felt):
end
end
Now other contracts can call your contract like:
IBalanceContract.increaseBalance(contract_address=contract_address,amount=amount)
Notice how the contract_address
was passed in as the first argument to the interface function, even though it was not explicitly defined in the interface/namespace
ㅤ This answer was originally posted on Triality
answered
6 months ago
Can you explain Cairo v0.10 usage functions as expressions?
caigo error: undefined: contracts.CounterCompiled
Any idea what this could be caused by?
ApeWorX: Why are the cairo and starknet plugins not installing properly?
How long does starkgate bridge process?
How does Account Abstraction improve the UX compared to other methods?
How can I pass an array of felt to call with Nile in StarkNet?