Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
target
.snfoundry_cache/
snfoundry_trace/
coverage/
profile/
24 changes: 24 additions & 0 deletions Scarb.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Code generated by scarb DO NOT EDIT.
version = 1

[[package]]
name = "deploy"
version = "0.1.0"
dependencies = [
"snforge_std_deprecated",
]

[[package]]
name = "snforge_scarb_plugin_deprecated"
version = "0.48.1"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:8b822345a82a4479cfbf8e605a4cd25c0a622585fd5640c4add524c5da5a8b55"

[[package]]
name = "snforge_std_deprecated"
version = "0.48.1"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:da9e4a8bbf8ba5f85e91e4b37a967b10eca0cb377a505eb7a8f37d0df721a874"
dependencies = [
"snforge_scarb_plugin_deprecated",
]
52 changes: 52 additions & 0 deletions Scarb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
[package]
name = "deploy"
version = "0.1.0"
edition = "2024_07"

# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html

[dependencies]
starknet = "2.11.4"

[dev-dependencies]
snforge_std_deprecated = "0.48.1"
assert_macros = "2.11.4"

[[target.starknet-contract]]
sierra = true

[scripts]
test = "snforge test"

[tool.scarb]
allow-prebuilt-plugins = ["snforge_std_deprecated"]

# Visit https://foundry-rs.github.io/starknet-foundry/appendix/scarb-toml.html for more information

# [tool.snforge] # Define `snforge` tool section
# exit_first = true # Stop tests execution immediately upon the first failure
# fuzzer_runs = 1234 # Number of runs of the random fuzzer
# fuzzer_seed = 1111 # Seed for the random fuzzer

# [[tool.snforge.fork]] # Used for fork testing
# name = "SOME_NAME" # Fork name
# url = "http://your.rpc.url" # Url of the RPC provider
# block_id.tag = "latest" # Block to fork from (block tag)

# [[tool.snforge.fork]]
# name = "SOME_SECOND_NAME"
# url = "http://your.second.rpc.url"
# block_id.number = "123" # Block to fork from (block number)

# [[tool.snforge.fork]]
# name = "SOME_THIRD_NAME"
# url = "http://your.third.rpc.url"
# block_id.hash = "0x123" # Block to fork from (block hash)

# [profile.dev.cairo] # Configure Cairo compiler
# unstable-add-statements-code-locations-debug-info = true # Should be used if you want to use coverage
# unstable-add-statements-functions-debug-info = true # Should be used if you want to use coverage/profiler
# inlining-strategy = "avoid" # Should be used if you want to use coverage

# [features] # Used for conditional compilation
# enable_for_tests = [] # Feature name and list of other features that should be enabled with it
13 changes: 13 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Starknet Foundry is the command line tool used to build and deploy Starknet contracts, sncast being used to perform Starknet RPC calls.

**Creating and Deploying Accounts**
The first step i nusing sncast is creating and deploying an account using the command *sncast account create --name --network*. This will spin up an account with an address, to which STRK tokens should then be sent, test tokens if using Sepolia, real tokens if on mainnet. The account should then be deployed using *sncast account deploy --name --network*. Accounts can also be imported from Ready or Braavos wallets.

**Declaring and Deploying Contract**
Starknet contracts havetoo be declared before deployment to be available to the network. Contracts are declared using *sncast account declare --network --contract-name*. This generates a class hash and transaction hash for the contract..The class hash is then used to deploy the contract using the command *sncast account deploy --network --class-hash*.

**Invoking and calling contracts**
When a contract is declared and deployed it's possible to interact with it i.e. manipulating it's read and write functions, which are referred to as calling and invoking respectively. Invoking or calling a contract requires the contract address, the function name and the required function arguments.

**Conclusion**
Starknet Foundry and sncast provide a robust set of tools that make working with and manipulating Starknet contracts easy and simple and their usefulness can't be overestimated in the building process.
11 changes: 11 additions & 0 deletions snfoundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Visit https://foundry-rs.github.io/starknet-foundry/appendix/snfoundry-toml.html
# and https://foundry-rs.github.io/starknet-foundry/projects/configuration.html for more information

# [sncast.default] # Define a profile name
# url = "https://starknet-sepolia.public.blastapi.io/rpc/v0_8" # Url of the RPC provider
# accounts-file = "../account-file" # Path to the file with the account data
# account = "mainuser" # Account from `accounts_file` or default account file that will be used for the transactions
# keystore = "~/keystore" # Path to the keystore file
# wait-params = { timeout = 300, retry-interval = 10 } # Wait for submitted transaction parameters
# block-explorer = "StarkScan" # Block explorer service used to display links to transaction details
# show-explorer-links = true # Print links pointing to pages with transaction details in the chosen block explorer
44 changes: 44 additions & 0 deletions src/lib.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/// Interface representing `HelloContract`.
/// This interface allows modification and retrieval of the contract balance.
#[starknet::interface]
pub trait IHelloStarknet<TContractState> {
/// Increase contract balance.
fn increase_balance(ref self: TContractState, amount: felt252);
/// Retrieve contract balance.
fn get_balance(self: @TContractState) -> felt252;
// change contract balance
fn set_balance(ref self: TContractState, amount: felt252);
//resets contract balance
fn reset_balance(ref self: TContractState);
}

/// Simple contract for managing balance.
#[starknet::contract]
mod HelloStarknet {
use starknet::storage::{StoragePointerReadAccess, StoragePointerWriteAccess};

#[storage]
struct Storage {
balance: felt252,
}

#[abi(embed_v0)]
impl HelloStarknetImpl of super::IHelloStarknet<ContractState> {
fn increase_balance(ref self: ContractState, amount: felt252) {
assert(amount != 0, 'Amount cannot be 0');
self.balance.write(self.balance.read() + amount);
}

fn get_balance(self: @ContractState) -> felt252 {
self.balance.read()
}

fn set_balance(ref self: ContractState, amount: felt252){
self.balance.write(amount);
}

fn reset_balance(ref self: ContractState){
self.balance.write(0);
}
}
}