This code represents a near-bos-webcomponent, which describes the version of the near-social-vm and its dependencies that is used to render the widgets.
The gateway bundleUrl
is configured in the bos.config.json. It can either be a relative path to a web component's distribution bundle (./gateway-bundle/dist
), such as this one, or it can use an existing bundle deployed to a remote url.
pnpm install
First, run the development server:
pnpm run dev
Open http://localhost:3000 in your browser to see the result.
pnpm run prod
This repository optionally includes a custom gateway for full control of the environment the Widgets run in.
Reasons for customization may include:
- Supporting more or different versions of wallets
- Introducing external APIs through custom elements (e.g.
Wallet
,Link
, orStripePayment
) - Query parameter pre-processing, router configurations, etc.
Follow the Customizing the Gateway guide for how to customize.
Once done, remember to Publish the build to NEARFS, and then this bundleUrl can be configured in bos.config.json
.
To publish, use the helper script to create and upload an IPFS CAR, deployed to nearfs with a signature from your NEAR account.
pnpm prepare:release <signer account> <signer key> <network>
This script will output the CID to terminal, as well as automatically save it under nearfs.cid in package.json.
Parameters:
signer account
: NEAR account to use for signing IPFS URL update transaction, see web4-deploysigner key
: NEAR account private key to use for signing. Should have base58-encoded key starting withed25519:
. Will attempt to sign from keychain (~/.near-credentials/) if not provided.network
: NEAR network to use. Defaults to mainnet.
This is an example of the NEARFS url, and you should replace with the cid you received above:
https://ipfs.web4.near.page/ipfs/bafybeiftqwg2qdfhjwuxt5cjvvsxflp6ghhwgz5db3i4tqipocvyzhn2bq/
After uploading, it normally takes some minutes before the files are visible on NEARFS. When going to the expected URL based on the IPFS address we saw above, we will first see the message Not found
.
Rather than deploying to a hosting provider like Vercel, this repository comes equipped with the scripts necessary to deploy to Web4, for fully decentralized web hosting. For full documentation, refer to web4-deploy.
Prerequisite: Have a web4 contract deployed. If you have not deployed one, create a web4 near subaccount (web4.YOUR_ACCOUNT.near) before continuing.
- Build the distribution bundle,
pnpm run build
- Use web4-deploy to deploy a web4 smart contract:
If deploying for the first time, append --deploy-contract
to automatically deploy a minimum web4 contract.
NEAR_ENV=testnet npx vgrichina/web4-deploy ./dist web4.[YOUR_ACCOUNT].testnet --nearfs
This will upload the build output (./dist
) to nearfs then set this will set the static url for web4_get to return.
Going forward, you can also configure and use the web4:deploy
command with the correct network and web4 account and run pnpm run web4:deploy
.
- Configure bos.config.json
gateway.bundleUrl
to be a relative path to this custom gateway's dist, e.g../gateway-bundle/dist
- Make sure you have the dev command running for this,
pnpm run dev:gateway
from root, orpnpm run dev
from this directory. - Once there has been as successful build, this prepares the
asset-manifest.json
needed to inject scripts into dev index.html. - Run the dev command in the root
pnpm run dev
. This will serve your widgets through the custom gateway. - Reload the page after making changes to the gateway-bundle.