Skip to content

Instantly share code, notes, and snippets.

View codeWhizperer's full-sized avatar
🎯
Focusing

Adegbite Ademola Kelvin codeWhizperer

🎯
Focusing
View GitHub Profile
import type { RpcProvider, WeierstrassSignatureType, BigNumberish } from "starknet";
import { Account, ec, encode, hash } from "starknet";
import type { Signer } from "../index";
import { SignatureConfig, SIG_CONFIG } from "../../constants";
export default class StarknetSigner implements Signer {
protected signer: Account;
public publicKey: Buffer;
public address: string;
private privateKey: string;
import { Account, RpcProvider, Signature, WeierstrassSignatureType, ec, encode, typedData, Signer as StarknetSigner } from "starknet";
import type { Signer } from "../index";
import { SignatureConfig, SIG_CONFIG } from "../../constants";
import { get_domain } from "./StarknetSigner";
export default class InjectedStarknetSigner implements Signer {
protected signer: Account;
public publicKey: Buffer;
public static address: string;
private static privateKey: string;
###SETUP
// config/index.tsx
import { defaultWagmiConfig } from "@web3modal/wagmi/react/config";
import { cookieStorage, createStorage, http } from "wagmi";
import { mainnet, sepolia } from "wagmi/chains";
// Your WalletConnect Cloud project ID
export const projectId = "8283a687dc64c79ec2996ba017e7cb5e";
// SPDX-License-Identifier: MIT
pragma solidity 0.8.18;
/*
REQUIREMENTS
1. Your contract will have public variables that store the details about your coin (Token Name, Token Abbrv., Total Supply)
2. Your contract will have a mapping of addresses to balances (address => uint)
3. You will have a mint function that takes two parameters: an address and a value.
The function then increases the total supply by that number and increases the balance
of the “sender” address by that amount
import React, { useContext } from "react";
import { NotificationContext } from "../../context/notification";
import { formatUnixTimeInNigeria } from "../../utils";
interface LogData {
opener?: string;
key?: string;
level?: string;
solver?: string;
culprit?: string;

Starknet Smart Contracts

A Starknet contract can be created by annotating a Cairo module with the #[starknet::contract] attribute.

Starknet contract don't require a main function. Functions in the contract module may be annotated as #[external(v0)] function. External functions can be called by the users of Starknet, and by other contracts.

The functions outside of these blocks are internal and cannot be accessed by users nor by other contract.

Functions in starknet contract have to explicitly define when writing to storage or reading from storage, by specifying the ref self:ContractState when writing to storage or self:@ContractState when reading from state.

// starknet3.cairo
// Joe liked Jill's work very much. He really likes how useful storage can be.
// Now they decided to write a contract to track the number of exercises they
// complete successfully. Jill says they can use the owner code and allow
// only the owner to update the contract, they agree.
// Can you help them write this contract?
// I AM NOT DONE
use starknet::ContractAddress;
#[starknet::interface]
trait IJoesContract<TContractState> {
fn get_owner(self:@TContractState) -> felt252;
}
#[starknet::contract]
mod JoesContract {
#[storage]
struct Storage{
#[starknet::interface]
trait IHelloStarknet<TContractState> {
fn increase_balance(ref self: TContractState, amount: felt252);
fn get_balance(self: @TContractState) -> felt252;
}
#[starknet::contract]
mod HelloStarknet {
#[storage]
struct Storage {
// starknet3.cairo
// Joe liked Jill's work very much. He really likes how useful storage can be.
// Now they decided to write a contract to track the number of exercises they
// complete successfully. Jill says they can use the owner code and allow
// only the owner to update the contract, they agree.
// Can you help them write this contract?
// I AM NOT DONE
use starknet::ContractAddress;