Skip to content

docs: add Contract.providerOrAccount explanation in migration guide #1462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

PhilippeR26
Copy link
Collaborator

Motivation and Resolution

Add in the migration guide an explanation to connect an account to a contract after contract instantiation.
v7:

myContract.connect(myAccount);

v8:

myContract.providerOrAccount = myAccount;

Usage related changes

N/A

Development related changes

N/A

Checklist:

  • Rebased to the last commit of the target branch (or merged it into my branch)

@@ -246,7 +246,7 @@ import { Contract } from 'starknet';
const contract = await Contract.factory({
contract: sierraContract, // Compiled Sierra contract
casm: casmContract, // Compiled CASM contract
account: account,
account: account, // optional
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The account isn't optional here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strange, because here it's optional :

const myTestContract = new Contract({ abi: compiledSierra.abi, address: deployResponse.contract_address });
  myTestContract.providerOrAccount = account0;

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type ContractOptions = {
    abi: Abi;
    address: string;
    /**
     * Connect account to read and write methods
     * Connect provider to read methods
     * @default defaultProvider
     */
    providerOrAccount?: ProviderOrAccount;
    /**
     * Class hash of the contract
     */
    classHash?: string;
} & CommonContractOptions;

Copy link
Collaborator Author

@PhilippeR26 PhilippeR26 Jul 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be same concept in both?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No because you cant do factory aka. Nor declare nor deploy without account.

To be honest optional provider or account on main class has no sense either, because without it you cant do anything with contract class

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be non-optional in both

Copy link
Collaborator Author

@PhilippeR26 PhilippeR26 Jul 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure.

  • Create a Contract without account/provider : I have seen this case to use myContract.functions() to get a list of functions of a contract.
  • Create a Contract with just a provider : Used to read Starknet (not write). Useful because you can read Starknet without asking to the user to connect an account.
  • Create a Contract with an account: Used to write Starknet.

Copy link
Member

@tabaktoni tabaktoni Aug 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Create a Contract with just a provider : Used to read Starknet (not write). Useful because you can read Starknet without asking to the user to connect an account.
  • Create a Contract with an account: Used to write Starknet.

Both these cases require a provider, so in those it is not optional.

  • Create a Contract without account/provider : I have seen this case to use myContract.functions() to get a list of functions of a contract.

There are better ways to extract a function, but let say this is the simplest one; in that case, one can provide a default or a dummy provider. However, this is an extreme edge case; one should use the Calldata parser to do this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants