sncast 101

This page showcases the standard usage of various sncast commands. For more in-depth explanation, please follow other guides from "sncast Overview".

Create and Deploy an Account

First, create an account contract ready for deployment. This generates the account details but doesn't put it on the network yet.

$ sncast account create \ --name my_account \ --network sepolia
Output:
command: account create add_profile: --add-profile flag was not set. No profile added to snfoundry.toml address: 0x[..] max_fee: [..] message: Account successfully created. Prefund generated address with at least <max_fee> STRK tokens. It is good to send more in the case of higher demand. After prefunding the address, run: sncast account deploy --network sepolia --name my_account

After creating an account, send enough STRK tokens to the address to cover the price of the account creation. At least max_fee amount of fri (1 STRK = 1018 fri) should be sent.

💡 Tip On Sepolia, this free faucet can be used to fund the account.

Then, deploy the account using the command that was provided in output, below After prefunding the address, run:

$ sncast account deploy \ --network sepolia \ --name my_account
Output:
command: account deploy transaction_hash: 0x[..] To see invocation details, visit: transaction: https://sepolia.starkscan.co/tx/0x[..]

Read more about accounts here

💡 Tip Existing accounts can be imported to sncast as well. See Importing Accounts for more information.

Calling a Contract

Calling a contract doesn't require an account

$ sncast call \ --contract-address 0x00cd8f9ab31324bb93251837e4efb4223ee195454f6304fcfcb277e277653008 \ --function get \ --arguments '0x123' \ --network sepolia
Output:
command: call response: [0x0]

Read more about calling contracts here

Sending a Transaction

To send a transaction, invoke a contract.

📝 Note --account argument must be passed before invoke subcommand. This is the same for other commands that send transactions as well.

$ sncast \ --account my_account \ invoke \ --contract-address 0x00cd8f9ab31324bb93251837e4efb4223ee195454f6304fcfcb277e277653008 \ --function put \ --arguments '0x123, 100' \ --network sepolia

💡 Tip --arguments flag supports various kinds of Cairo types including structs --arguments 'MyStruct { a: 1, b: 2 } and enums --arguments MyEnum::Variant1.

See Calldata Transformation for more details.

Output:
command: invoke transaction_hash: 0x[..] To see invocation details, visit: transaction: https://sepolia.starkscan.co/tx/0x[..]

Read more about sending transactions here

Declare a Contract

sncast uses scarb to build contracts and can find contracts by their names (part after mod for #[starknet::contract]). To declare a contract, simply pass it name to sncast.

💡 Tip There is no need to run scarb build before declaration. sncast will do that automatically

Create a project

snforge new my_project

From inside the my_project directory run

$ sncast \ --account my_account \ declare \ --contract-name HelloStarknet \ --network sepolia
Output:
command: declare class_hash: 0x[..] transaction_hash: 0x[..] To see declaration details, visit: class: https://sepolia.starkscan.co/class/0x[..] transaction: https://sepolia.starkscan.co/tx/0x[..]

Read more about declaring contracts here

Deploy a Contract

Provide a class hash of your contract obtained from declaring it. It's the part after class_hash:.

$ sncast \ --account my_account \ deploy \ --class-hash 0x06813150c8b6256546fe2324b49f85021a207b6a383fc207d587f4bfacec00d8 \ --network sepolia
Output:
command: deploy contract_address: 0x[..] transaction_hash: 0x[..] To see deployment details, visit: contract: https://sepolia.starkscan.co/contract/0x[..] transaction: https://sepolia.starkscan.co/tx/0x[..]

Read more about deploying contracts here