NEWTON
Asked
10 months ago
47
views
0
I have the following code:
from starkware.cairo.common.uint256 import Uint256
func main():
test()
return()
end
func test() -> (res : felt):
alloc_locals
local a : Uint256 = Uint256(low=1, high=0)
if 1 == 1:
local a : Uint256 = Uint256(low=2, high=0)
end
return (res = a)
end
But I keep getting Error: code:20:19: Reference 'a' was revoked.
return (res = a)
^
What is a good pattern for solving this issue?
ㅤ This question was originally posted on Triality
0
You can make the dynamic variable in the conditional a felt and use the following pattern:
Hopefully there will be some updates to the language in the future though, so this won't be an issue
from starkware.cairo.common.uint256 import Uint256
func main():
test()
return()
end
func test() -> (res : felt):
alloc_locals
local a
if 1 == 1:
a = 2
else:
a = 3
end
local b: Uint256 = Uint256(low=a, high=0)
return (res = a)
end
ㅤ This answer was originally posted on Triality
answered
10 months ago
Cairo error "Expected expression of type 'starkware.cairo.common.uint256.Uint256' to have an address."
Fixed Point pow operation error
How do you optimize gas in Cairo with Uint256/felt?
Cairo Error: 'range_check_ptr' cannot be used as an implicit return value. Consider using a 'with' statement.
How to import uint256 in Cairo?
How can I send a Uint256 amount of ERC20 tokens from L1 to starknet? And how should I build my payload for "sendMessageToL2" to match the Uint256 format of Cairo?
Is uint256 math operators like uint256_le safe? Why do I need to use uint256_check?
I can't find info on what `vm_enter_scope` does within hints in the cairo-lang repo
Implementing the connect wallet. Can you help about connectors?
Can tempvar be of a different type, say U256?
Do you think in Fture ETH will be Better than BTC
How do I check that my Solidity compiler version is >= 0.8.0 ?
How does warp handles the contract solidity version?
Is there a javascript version of StarkEx playground?