Skip to content

Browser support #31

@rkalis

Description

@rkalis

Currently, the CashScript JavaScript SDK can only be used inside NodeJS, and not inside a browser environment. There are several things that cause this.

  1. 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.
  2. Use of filesystem operations in the SDK that are incompatible with a browser environment. Contract.compile, Contract.import, instance.export, Artifacts.require, Artifacts.export, CashCompiler.compileFIle all read from or write to the local filesystem using fs and path.

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 like Contract.fromContract. Artifacts can be imported using the regular JavaScript require 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.

Metadata

Metadata

Assignees

Labels

cashc-compilerRelates to the cashc compilerjavascript-sdkRelates to the CashScript JavaScript SDK

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions