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

ts: Add views #1695

Merged
merged 33 commits into from
Apr 3, 2022
Merged

Conversation

tomlinton
Copy link
Contributor

Since #1598 instruction return types are in the IDL, and we know which instructions are mutable from the accounts, so we can add an <instruction>.view() to the client and the methods API builder that parses the logs and deserializes the return data.

E.g.

assert(
      new anchor.BN(99).eq(await callerProgram.methods.returnU64().view())
);

This came from looking at #566 which called for an explicit attribute for marking views, but I don't think we need it since #1598. Might be wrong though!

Closes #566.

@armaniferrante
Copy link
Member

The no macro approach is much better!

@armaniferrante armaniferrante merged commit 8fb942e into coral-xyz:master Apr 3, 2022
@armaniferrante
Copy link
Member

armaniferrante commented Apr 3, 2022

I forgot to add the changelog. Will do next.

@zikyfranky
Copy link

I know this is not the right place to do this, but does anyone have any idea why .view() on the client side triggers wallet signing?

Had to recreate the logic so as to get it working on my app.

@dev-johnny-gh
Copy link

dev-johnny-gh commented Apr 1, 2024

@zikyfranky How they implement the view method is that they sign the transaction and simulate it on the endpoint(connection) and get the result, it's a very bad design compared to solidity.

@zikyfranky
Copy link

@dev-johnny-gh it really is a bad design asking end users to sign a VIEW call, it doesn't make sense whatsoever.

Thanks for the reply.

@jakerumbles
Copy link

@zikyfranky Running into the same issue here. Can't have phantom popping up left and right on our dapp just for read calls to the chain. How did this design pass beta testing?

@zikyfranky
Copy link

@zikyfranky Running into the same issue here. Can't have phantom popping up left and right on our dapp just for read calls to the chain. How did this design pass beta testing?

Exactly my thought haha.. it doesn't make any sense whatsoever to have end users sign READ instructions..

Anyways, created a gist that contains my fix, basically was a remake of the logic behind the view function
https://gist.github.com/zikyfranky/da0117a0e587899e39ffea10255abc1f

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.

#[view] macro
5 participants