The Lit JavaScript SDK provides developers with a framework for implementing Lit functionality into their own applications. Find installation instructions in the docs to get started with the Lit SDK based on your use case:
The following commands will help you start developing with this repository.
First, install the dependencies via yarn:
yarn
Building
You can build the project with the following commands:
// for local development - It stripped away operations that don't matter for local dev
yarn build:dev
// you should never need to use yarn build unless you want to test or publish it
yarn build
Running Test Apps
The test apps are configured to automatically import all modules and expose all module functions. For browsers, you can access these functions using window.LitJsSdk_<package_name>.<function_name>
// Running apps...
// react: http://localhost:4003
// nodejs: in the terminal
yarn apps
or running individually
// react
yarn nx run react:serve
// nodejs
yarn nx run nodejs:serve
Run unit tests
yarn test:unit
Run E2E tests in nodejs
yarn test:local
Advanced
Creating a new library
By default, NX provides a command to generate a library
nx generate @nx/js:library. However, it doesn't have an esbuild built-in so that we've created a custom tool that modify the build commands.
yarn gen:lib <package-name> <tag>
Create a new react demo app using the Lit JS SDK
yarn tools --create --react contracts-sdk --demo
Deleting a package or app
// delete an app from ./app/<app-name>
yarn delete:app <app-name>
// delete a package from ./packages/<package-name>
yarn delete:package <package-name>
Building
yarn build
Building target package
yarn nx run <project-name>:build
Building Local Changes
During development you may wish to build your code changes in packages/ in a client application to test the correctness of the functionality.
If you would like to establish a dependency between packages within this monorepo and an external client application that consumes these packages:
Run npm link at the root of the specific package you are making code changes in.
cd ./packages/*/<package-name>
npm link
Build the packages with or without dependencies
yarn build
# or
yarn nx run lit-node-client-nodejs:build --with-deps=false
In the client application, run npm link <package> --save to ensure that the package.json of the client application is updated with a file: link to the dependency. This effectively creates a symlink in the node_modules of the client application to the local dependency in this repository.
cd path/to/client-application
npm link <package> --save
Having done this setup, this is what the development cycle looks like moving forward:
Make code change
Rebuild specific package
Rebuild client application.
Publishing
You must have at least nodejs v18 to do this.
Install the latest packages with yarn install
Run yarn bump to bump the version
Build all the packages with yarn build
Run the unit tests with yarn test:unit & e2e node tests yarn test:local locally & ensure that they pass
Update the docs with yarn gen:docs --push
Finally, publish with the @cayenne tag: yarn publish:cayenne
The following will serve the react testing app and launch the cypress e2e testing after
yarn test:local
Environments
There are currently three environments can be tested on, each of which can be generated from a custom command, which would automatically import all the libraries in ./packages/*. The UI of HTML & React are visually identical but they are using different libraries.
E2E Testing with Metamask using Cypress (for Browser)
React
// E2E React
yarn tools --test --e2e react
Testing with a Local Lit Node
First, deploy your Lit Node Contracts, since the correct addresses will be pulled from the ../lit-assets/blockchain/contracts/deployed-lit-node-contracts-temp.json file.