Skip to content

Instantly share code, notes, and snippets.

#[starknet::interface]
trait IMyFirstContract<ContractState> {
fn get_value(self: @ContractState) -> u64;
}
#[starknet::contract]
mod MyFirstContract {
#[storage]
struct Storage {
value: u64
@DavideSilva
DavideSilva / hello_starknet.cairo
Created May 30, 2023 14:02
Implementation of StorageAccess trait for CustomStruct in Cairo 1
#[contract]
mod HelloStarknet {
use starknet::StorageAccess;
use starknet::StorageBaseAddress;
use starknet::SyscallResult;
use starknet::storage_read_syscall;
use starknet::storage_write_syscall;
use starknet::storage_address_from_base_and_offset;
use traits::{Into, TryInto};
use option::OptionTrait;
#[derive(Copy, Drop)]
struct MyStruct {
val: felt,
}
trait MyTrait<T> {
fn is_green(self: @T) -> bool;
}
impl RGBImpl of MyTrait::<MyStruct> {
#[contract]
mod HelloStarknet {
struct Storage {
balance: felt,
}
#[external]
fn increase_balance(amount: felt) {
let new_balance = balance::read() + amount;
balance::write(new_balance);
@DavideSilva
DavideSilva / struct_comparison.cairo
Created March 3, 2023 19:52
custom struct comparison in Cairo 1
#[derive(Drop)]
struct MyStruct {
first_attribute: u8,
second_attribute: u8,
}
impl MyStructPartialEq of PartialEq::<@MyStruct> {
fn eq(a: @MyStruct, b: @MyStruct) -> bool {
*a.first_attribute == *b.first_attribute & *a.second_attribute == *b.second_attribute
}
@DavideSilva
DavideSilva / Ballot.sol
Created May 1, 2022 19:19
Ballot contract with voting time limit for ZKUni
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
/**
* @title Ballot
* @dev Implements voting process along with vote delegation
*/
contract Ballot {
@DavideSilva
DavideSilva / HelloWorld.sol
Created May 1, 2022 18:30
HelloWorld Solidity contract for ZKUni
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
contract HelloWorld {
uint256 number;
/**
* @param _number value to store
*/
function storeNumber(uint256 _number) public {
@DavideSilva
DavideSilva / keybase.md
Created June 7, 2019 10:46
Keybase proof

Keybase proof

I hereby claim:

  • I am davidesilva on github.
  • I am davidesilva (https://keybase.io/davidesilva) on keybase.
  • I have a public key ASACnPLdBDZP1sXlAYC7TKNqaMlBZswZbovK0vC88PHjqwo

To claim this, I am signing this object: