-
Notifications
You must be signed in to change notification settings - Fork 80
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
Browser support #31
Comments
@rkalis Regarding (2): During the SLPVH we were thinking about using cashscripts in our client-side app. Initially, to overcome the issues of filesystem operations (fs and path), we aliased fs and path to https://github.com/jvilk/BrowserFS equivalent, and had some success with it. Might be a good workaround, I don't know. |
@alcipir Is there any public fork repo available? |
Hey @pavel-main! @alcipir created the cashscript-components repo in which he got CashScript running in web. Ideally, the code @alcipir used to make it work in that repository should be integrated into the build process for the |
Incoming PR #52, need help with testing. |
Hello! I'm glad to see some activity with this. I just sat down for a bit to get this working in the browser as well. Below is a screenshot of what seems to be working. I'm curious if I'm missing anything and I'm hesitant to say it is working because I still need to learn BitBox API and Bitcoin Scripting in general to really test it and get rolling, God willing. AFAIK as long as we:
And
Then you'd be get the result in the screenshot above. |
This is released in v0.3.2 |
Currently, the CashScript JavaScript SDK can only be used inside NodeJS, and not inside a browser environment. There are several things that cause this.
antl4ts
might be incompatible with a browser environment.antlr4ts
has only been tested to work in a NodeJS environment, but there is an open PR for browser support (antlr4ts#413). This would allow compilation of CashScript contracts in-browser. However, for use of Artifacts, it is not needed to use the compiler in-browser.Contract.compile
,Contract.import
,instance.export
,Artifacts.require
,Artifacts.export
,CashCompiler.compileFIle
all read from or write to the local filesystem usingfs
andpath
.The solution to (1) is to wait for this PR to be merged, or contribute to it if necessary.
For (2) we can decide to replace these functions with their equivalents that don't need filesystem access. This would mean that users need to read in the
.cash
file themselves, then pass in the string into a function likeContract.fromContract
. Artifacts can be imported using the regular JavaScriptrequire
since they're just JSON files, which makes it all a bit easier when just dealing with artifacts.In this case it could be valuable to have a Truffle-like workflow for CashScript that handles contract compilation and instantiation, and automatically creates artifact JSON files. Then the JavaScript (or potentially Python, Rust, etc.) application just needs to import the Artifact JSON, which is usually quite simple.
The
cashc
CLI will always need filesystem access any way, so we should figure out how to make this available to the CLI, while the NPM package doesn't necessarily require it when it is installed into other projects.We need to think more about the best and most user-friendly way to enable browser support for CashScript.
The text was updated successfully, but these errors were encountered: