Skip to content
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

Extend Contract class to enable view function calls without Account #1325

Merged
merged 4 commits into from
Mar 27, 2024

Conversation

denbite
Copy link
Contributor

@denbite denbite commented Mar 22, 2024

Pre-flight checklist

  • I have read the Contributing Guidelines on pull requests.
  • Commit messages follow the conventional commits spec
  • If this is a code change: I have written unit tests.
  • If this changes code in a published package: I have run pnpm changeset to create a changeset JSON document appropriate for this change.
  • If this is a new API or substantial change: the PR has an accompanying issue (closes #0000) and the maintainers have approved on my working plan.

Motivation

Many developers complained about the confusing implementation of the Contract class, which requires an Account parameter in the constructor even for view function calls

This PullRequest solves the issue by extending the interface of the first parameter in the constructor and additionally enables full backward compatibility with older versions

Old implementation

// account is required
const contract = new Contract(account, options);

contract.view_method({});
contract.call_method({ args: {} });

New implementation

const contract = new Contract(connection, options);

// no account required
contract.view_method({});

// signerAccount must be specified to sign the transaction
contract.call_method({ signerAccount: account, args: {} });

Test Plan

Related issues/PRs

#1066
#1064

Copy link

changeset-bot bot commented Mar 22, 2024

🦋 Changeset detected

Latest commit: 24a01dc

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@near-js/accounts Minor
@near-js/cookbook Patch
near-api-js Patch
@near-js/wallet-account Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Collaborator

@vikinatora vikinatora left a comment

Choose a reason for hiding this comment

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

Looks very good, only one comment and I belive the biggest change I request is with the changeset, as there are quire a few breaking changes. Please adjust the changeset file accordingly(should be a major version increment most probably). If you're not sure about how semantic versioning works, you can check the rules out here

const result = await connection.provider.query<CodeResult>({
request_type: 'call_function',
...blockQuery,
account_id: jsContract ? connection.jsvmAccountId : contractId,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Everything connected to jsvmAccountId is obsolete and will be removed very soon from near-api-js. Let's not add it to new functionality.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The PR solves another issue and doesn't know anything about jsvmAccountId, this particular change has taken away function from the Account class and moved into another place
I wouldn't remove jsvmAccountId right here as it's a breaking change that may cause issues if you don't mind (and I assume you're preparing another PR out there that does remove it)

@denbite
Copy link
Contributor Author

denbite commented Mar 26, 2024

Looks very good, only one comment and I belive the biggest change I request is with the changeset, as there are quire a few breaking changes. Please adjust the changeset file accordingly(should be a major version increment most probably). If you're not sure about how semantic versioning works, you can check the rules out here

These changes were made to be backward compatible, so releasing them to users shouldn't cause any issues (and it's not a breaking change from that perspective of view)

vikinatora
vikinatora previously approved these changes Mar 26, 2024
@vikinatora vikinatora merged commit f287962 into near:master Mar 27, 2024
3 checks passed
This was referenced Mar 27, 2024
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.

2 participants