-
I saw this question today in discord... Hi, how do I call a public interface method from the ui? I can connect the vstorage, get the contract, use ChainStorageWatcher to get the instance but I don't find any tutorial on how to call a method defined in the public interface |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 9 replies
-
As explained in Building Client Dapps
If the public facet method is a "get", the client often wants not just one answer, but a stream of answers as the current value changes. In that case, you can somewhat simulate a call on the public facet by
If the public facet method is not a "get", then you should be able to accomplish it with invitations and offers as discussed in the docs above. I can imagine this is overly brief. Please ask questions where it's not clear. Or perhaps one of my colleagues will find a moment to give examples. |
Beta Was this translation helpful? Give feedback.
-
EVM analog: views |
Beta Was this translation helpful? Give feedback.
The agoric platform doesn't have a special case for query methods in contracts. (Whether it could or should is a longer discussion...)
Instead, it has vstorage / chainStorage.
The addNote method can publish to chainStorage, and the ui code can query vstorage.
I see @amessbee put together a quick example where the contract does...
-- https://github.com/amessbee/dapp-med-rep/blob/b0f3adb041d9383a7badee12b51bf457cce0e473/contract/src/med-rec-contract.js#L84C1-L84C66
The
publishHandler
function is close to anaddNote
function. Since this contract isn't actually trading assets, the indirection aroundmakePublishInvitation
is unf…