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
Open
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: 4 additions & 1 deletion www/docs/guides/migrate.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

constructorCalldata: {
name: 'Token',
symbol: 'ERC20',
Expand All @@ -259,6 +259,9 @@ const contract = await Contract.factory({
unique: true, // optional
deployer: account.deployer, // optional
});

// if `account` property has not been defined above, it can be added later with:
contract.providerOrAccount = myAccount;
```

### Removed Helper Functions
Expand Down