diff --git a/components/Starknet/modules/architecture-and-concepts/pages/smart-contracts/contract-classes.adoc b/components/Starknet/modules/architecture-and-concepts/pages/smart-contracts/contract-classes.adoc index 83f6636ff1..aa6a6e5ff1 100644 --- a/components/Starknet/modules/architecture-and-concepts/pages/smart-contracts/contract-classes.adoc +++ b/components/Starknet/modules/architecture-and-concepts/pages/smart-contracts/contract-classes.adoc @@ -22,6 +22,14 @@ A contract class does not necessarily require a deployed instance in Starknet. A contract instance has a nonce, the value of which is the number of transactions originating from this address plus 1. For example, when you deploy an account with a `DEPLOY_ACCOUNT` transaction, the nonce of the account contract in the transaction is `0`. After the `DEPLOY_ACCOUNT` transaction, until the account contract sends its next transaction, the nonce is `1`. +== Declaration and deployment + +Starknet separates the process of declaring a contract class from deploying contract instances. This separation offers several advantages: +[horizontal] +Gas optimization:: The contract code is stored on the network only once, reducing gas costs for subsequent deployments. +Reusability:: Multiple instances of the same contract can be deployed without repeatedly sending the full code. +Version control:: It allows for better management of contract versions across different deployments. + == Working with classes [horizontal,labelwidth=20,role="stripes-odd"] diff --git a/components/Starknet/modules/quick-start/images/declaration-process.png b/components/Starknet/modules/quick-start/images/declaration-process.png new file mode 100644 index 0000000000..963e01b3ec Binary files /dev/null and b/components/Starknet/modules/quick-start/images/declaration-process.png differ diff --git a/components/Starknet/modules/quick-start/images/deployment-process.png b/components/Starknet/modules/quick-start/images/deployment-process.png new file mode 100644 index 0000000000..95845495e2 Binary files /dev/null and b/components/Starknet/modules/quick-start/images/deployment-process.png differ diff --git a/components/Starknet/modules/quick-start/pages/declare-a-smart-contract.adoc b/components/Starknet/modules/quick-start/pages/declare-a-smart-contract.adoc index 7e2b19df3e..806c3aebfd 100644 --- a/components/Starknet/modules/quick-start/pages/declare-a-smart-contract.adoc +++ b/components/Starknet/modules/quick-start/pages/declare-a-smart-contract.adoc @@ -21,11 +21,21 @@ Deploying a smart contract in Starknet requires two steps: * Declaring the class of your contract, i.e. sending your contract's code to the network. * Deploying a contract, i.e. creating an instance of the code you previously declared. +image::declaration-process.png[] + [TIP] ==== If you require a smart contract for testing, you can use this sample contract, link:https://github.com/starknet-edu/starknetbook/blob/main/examples/vote-contracts/src/lib.cairo[`lib.cairo`], from the Starknet Book. ==== +=== What is Declaration? + +Declaration is the process of submitting your contract's code to the Starknet network, making it available for future deployments. It's a one-time process for each unique contract code. Think of declaration as registering a blueprint for your contract with the network. + +Contract classes are analogous to classes in Object Oriented Programming. The class is defined once, and there can be many instances of it. + +For more details on declaration and its benefits, see xref:contract-classes.adoc[Contract classes and instances]. + == Compiling a smart contract You can compile a smart contract using the Scarb compiler. @@ -64,26 +74,6 @@ The compiled contract will be saved in the `target/dev/` directory. The contract is now compiled and ready to be deployed. Next you will need to declare an RPC provider within your contract. -== Setting an RPC provider - -To interact with the Starknet network, you need to set an RPC endpoint within Starkli. - -The following are the RPC providers available for Starknet: - -[cols="1,2"] -|=== -|Provider name |Description - -|Infura or Alchemy -|Use a provider like Infura or Alchemy. - -|Custom configuration -|Set up your own node and use the RPC provider of your node. More information on this can be found within the link:https://book.starknet.io/chapter_4/node.html[Starknet Book]. - -|=== - -For demonstration purposes, the Starknet Sequencer's Gateway is used in the below steps. - == Declaring a smart contract A contract can be declared on Starknet using the following command: @@ -159,3 +149,5 @@ If the contract you are declaring has previously been declared by someone else, ---- Not declaring class as its already declared. Class hash: ---- + +In this case, you can still use the block explorer to see the contract class hash in the blockchain. diff --git a/components/Starknet/modules/quick-start/pages/deploy-a-smart-contract.adoc b/components/Starknet/modules/quick-start/pages/deploy-a-smart-contract.adoc index 5c80807ff6..fd6305ce32 100644 --- a/components/Starknet/modules/quick-start/pages/deploy-a-smart-contract.adoc +++ b/components/Starknet/modules/quick-start/pages/deploy-a-smart-contract.adoc @@ -21,6 +21,10 @@ Deploying a smart contract in Starknet requires two steps: * Deploying a contract, i.e. creating an instance of the code you previously declared. +image::deployment-process.png[] + +For more details on the declaration and deployment processes, see xref:contract-classes.adoc[Contract classes and instances]. + == Deploying a smart contract Deploying a smart contract involves instantiating it on Starknet. The deployment command requires the class hash of the smart contract and any arguments expected by the constructor. @@ -45,6 +49,7 @@ starkli deploy \ --network=sepolia ---- + == Expected result After running the command and adding your password, you will see an output similar to this: @@ -58,3 +63,39 @@ Contract deployed: 0x014825acb37c36563d3b96c450afe363d2fdfa3cfbd618b323f95b68b55 ---- The smart contract has now been deployed to Starknet. + +=== Verifying the Deployment + +To verify your contract deployment: + +* Using Starkli: +You can use the following command to retrieve the class hash of your deployed contract: + +[source,bash] +---- +starkli class-hash-at --network=sepolia +---- + +* Using a Block Explorer: + +You can use block explorers like https://voyager.online/ or https://starkscan.co/ to search for the contract address. + +[IMPORTANT] +==== +Remember to select the Sepolia testnet in these block explorers when searching for your deployed contract. +==== + +Your smart contract is now live on the Starknet network, ready to interact with users and other contracts. + +=== Potential deployment errors + +When using Starknet SDKs like starknet.js, starknet.py, or starknet-rs, you might encounter the following error during deployment: + +[source,bash] +---- +Requested ContractAddress(PatriciaKey()) is unavailable for deployment. +---- + +This error means that a contract is already deployed at the computed address. The address is a function of the class_hash, deployer_address (if specified), salt, and constructor_calldata_hash. + +To resolve this issue, make sure to provide a different salt value. This ensures you're not attempting to override an already deployed contract.