Search code examples
nearprotocol

near-api-js What is the difference between contractId and account.accountId in the contract interface?


Contract constructor takes both account: Account and contractId: string, but Account already provides account id of the contract as account.accountId. What is the difference between these two? https://github.com/near/near-api-js/blob/master/src/contract.ts#L22

Upd: We can even see in tests that they are passed the same value here: https://github.com/near/near-api-js/blob/master/test/test-utils.js#L39


Solution

  • account.accountId specifies who is signing transaction, i.e. account which is performing actions.

    contractId specifies the account name of contract which is receiving transactions.

    They can be the same if it's necessary to perform actions on behalf of contract's account but basically this only applies to contact owners. They won't be the same if e.g. you have user logged in using WalletConnection and calling third-party contract.