-
Notifications
You must be signed in to change notification settings - Fork 249
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
Abstractions If Using JS SDK #867
Comments
What does this mean? Contracts haven't been written yet? |
See this discussion (i'll edit the original post to point to the discussion as well). |
As @thisisjoshford put it better dev x to have:
be:
|
We should give users the ability to set custom JSVM accountId. Some of them will deploy their own JSVMs. It can be an optional parameter that defaults to Now all the |
Overview
Currently if you are using the javascript SDK, you're forced into an isolated environment similar to aurora. This isolated environment is called an enclave. The differences between the enclave and WASM (Rust and AS) approaches are outlined in the following table (as outlined in this PR:
If you'd like to check out my WIP quickstart guide for using the enclave, checkout this draft PR. In addition, I've made a game using the JS SDK (which I'm working on a frontend for). This game can be found here.
Abstractions made with the NEAR-CLI
The current development cycle when creating a javascript is as follows:
If you want to deploy the contract, you need to call a method on the enclave contract (
jsvm.testnet
) and pass the base64 as an argument. Using the NEAR-CLI, this looks as such:This is contrast with Rust and AS as to deploy a contract, you would simply run:
The differences here are that using the JSVM, the contract is never actually "deployed" and simply lives in the state of the JSVM contract. Your account ID will have no contract deployed to it. When using Rust or AS, the contract is deployed to your account and lives on your account.
This deploy functionality has been abstracted to look more like the AS and Rust deployment command in this PR and there is an ongoing discussion found here. The new command is:
This makes it easier for developers to interact with their contracts and they don't need to know about the enclave. This sort of abstractions has been made for calling, viewing, and deploying smart contracts to the JSVM enclave.
Using NAJ Right Now
The conventional way to interact with a deployed smart contract on NEAR is to do something as follows:
You're signing a transaction whereby the receiver is the actual contract ID and you're passing in the arguments as key-value pairs. If you'd like to interact with a javascript contract that's deployed to the enclave, the way you use NAJ is different. The first thing you need to do is to introduce an encoding function like such:
Once you have the encode function, you need to encode your arguments and pass them in like so:
If you want to perform a view call, you would need to do this:
The Ask
If we can attempt to mirror what is being done in the NEAR-CLI and abstract some of this encoding and strange behaviour away from the user, it would provide a better UX. We can introduce an optional flag for whether or not users have an enclave JS contract and if they do, the encoding can happen behind the scenes and the receiver ID can be set to the JSVM account behind the scenes.
We could have:
which would do this behind the scenes:
let args = encodeCall("contract.benji.testnet", 'newGame', '["benjiman.testnet", "patrick.testnet"]'); const result = await wallet.account().functionCall({ contractId: "jsvm.testnet", methodName: 'call_js_contract', args, gas: "300000000000000" });
Additional discussions
If you want to read more about some of the discussions going on surrounding the JS SDK, please check this out.
The text was updated successfully, but these errors were encountered: