Cairo 1.0 Q&A #2267
Replies: 9 comments 9 replies
-
Hi, Is it possible to execute bitwise operations on felts?.
|
Beta Was this translation helpful? Give feedback.
-
I try to declare the official hello_starknet contract with command: And I get error:
Maybe my starknet version is wrong? Or just the official contract does't work? starknet version: |
Beta Was this translation helpful? Give feedback.
-
When I update a mutable variable inside a break condition of a loop it throw an error. This is the code:
and this is the error:
This error is kind of odd, shouldn't this logic valid in Cairo1? |
Beta Was this translation helpful? Give feedback.
-
How to write code in Cairo that is similar to Rust's
use case:
|
Beta Was this translation helpful? Give feedback.
-
In /// Generate getters and setters skeleton for a non-mapping member in the storage struct.
fn handle_legacy_mapping_storage_var(address: &str) -> String {
format!(
"
mod $storage_var_name$ {{$extra_uses$
use starknet::SyscallResultTrait;
use starknet::SyscallResultTraitImpl;
fn address(key: $key_type$) -> starknet::StorageBaseAddress {{
starknet::storage_base_address_from_felt252(
hash::LegacyHash::<$key_type$>::hash({address}, key))
}}
fn read(key: $key_type$) -> $value_type$ {{
// Only address_domain 0 is currently supported.
let address_domain = 0_u32;
starknet::StorageAccess::<$value_type$>::read(
address_domain,
address(key),
).unwrap_syscall()
}}
fn write(key: $key_type$, value: $value_type$) {{
// Only address_domain 0 is currently supported.
let address_domain = 0_u32;
starknet::StorageAccess::<$value_type$>::write(
address_domain,
address(key),
value,
).unwrap_syscall()
}}
}}"
)
} Note the line
The result of the inner hash is in the |
Beta Was this translation helpful? Give feedback.
-
How can I generate from a cairo file the |
Beta Was this translation helpful? Give feedback.
-
how can i get current block number in cairo contract? Just like block.number in solidity |
Beta Was this translation helpful? Give feedback.
-
Hello! I'm currently utilizing the following crate: Here are my questions:
Thanks in advance for any clarification here! |
Beta Was this translation helpful? Give feedback.
-
Hello! How can this be done? Here's an example: #[starknet::interface]
trait ITest<TContractState> {}
#[starknet::contract]
mod Test {
#[storage]
struct Storage {
byte_array: ByteArray
}
#[constructor]
fn constructor(ref self: ContractState, byte_array: ByteArray) {
self.byte_array.write(byte_array);
}
}
use starknet::ClassHash;
#[starknet::interface]
trait IFactory<TContractState> {
fn create_test(self: @TContractState, class_hash: ClassHash, byte_array: ByteArray);
}
#[starknet::contract]
mod Factory {
use starknet::syscalls::{deploy_syscall};
use starknet::ClassHash;
use starknet::SyscallResultTrait;
#[storage]
struct Storage {}
#[abi(embed_v0)]
impl Factory of super::IFactory<ContractState> {
fn create_test(self: @ContractState, class_hash: ClassHash, byte_array: ByteArray) {
let mut constructor_calldata: Array::<felt252> = array![];
constructor_calldata.append(byte_array.into()); // <-- here's the problem
// Trait has no implementation in context: core::traits::Into::<core::byte_array::ByteArray, core::felt252>.
let (deployed_address, _) = deploy_syscall(
class_hash, 0, constructor_calldata.span(), false
)
.unwrap_syscall();
}
}
} |
Beta Was this translation helpful? Give feedback.
-
Ask all your questions about Cairo 1.0
Beta Was this translation helpful? Give feedback.
All reactions