Contract classes and instances
As in object-oriented programming, Starknet distinguishes between a contract and its implementation by separating contracts into classes and instances.
Contract classes
A contract class is the definition of a contract. It includes Cairo byte code, hint information, entry point names, and everything that defines its semantics.
Each class is uniquely identified by its class hash, comparable to a class name in traditional object-oriented programming languages.
Contract instances
A contract instance is a deployed contract that corresponds to a class. Only contract instances act as true contracts, in that they have their own storage and can be called by transactions or other contracts.
A contract class does not necessarily have a deployed instance in Starknet.
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
.
Working with classes
Adding new classes |
To introduce new classes to Starknet’s state, use the |
Deploying instances |
To deploy a new instance of a previously declared class, use the |
Using class functionality |
To use the functionality of a declared class without deploying an instance, use the |