Skip to main content

Sites CLI (site.mjs)

site.mjs is the reference command line to publish and manage sites. It is a Node.js script. It signs with a private key file and pays in IOTA from that account.

Not public yet

The CLI lives in the project repository, which is not public yet. Most users should use the app, which does the same from a browser wallet.

Commands​

CommandWhat it does
publish <folder>Publishes the folder as a new site.
update <folder> <site>Updates an existing site with the folder.
deploy <folder>Publishes the first time and updates afterwards, using the object_id of ws-resources.json, which it writes. Without object_id, if the account already has a site with the same name, it stops before paying anything: it may be that one, from a deploy cut off before it wrote its ID (put it in object_id; for a second site with that name, use publish).
map <site>Lists the resources of a site (path, content-type, blob ID, patch), its routes and its redirects.
convert <0x… or base36>Converts a Site ID to base36 and back.
destroy <site>Deletes the blobs (except those another of your sites uses, and none of a site another account sent you), removes the resources and burns the Site. --keep-blobs deletes none.
renew [<site>…] --epochs NExtends the blobs of the site without uploading anything.
names [<site>]Lists the IOTA Names names of the account (with their expiry) and the ones that lead to a site, and how; with <site>, only those that lead to it.
name <site> <name.iota>Makes the name lead to the site, as Add a name in the app: a name of the account gets the site's link in its website field (its target address does not change); a subname of one (blog.alice.iota) becomes a leaf subname with the site as its target.
unname <name.iota>The name no longer leads to its site: it removes the website field (and the target address, if it was the site too) or the leaf subname.

<site> can be the object ID (0x…), its base36 form or an IOTA Names name (name.iota) that leads to it, read as the portal does: its website field, or else its target address. The IOTA Names commands work with the names whose NFT the --key account holds; see IOTA Names.

Options​

OptionDefaultMeaning
--key <file>File with the private key (iotaprivkey1…) of the account that pays and owns the site. Keep it secret.
--epochs <N>1Epochs to store the new files, and up to which the blobs in use are renewed (current epoch + N). At most 53.
--permanentoffStore the files as permanent (not deletable) blobs. By default they are deletable.
--name "…"Name of the site; overrides site_name.
--max-quilt <bytes>512 MiBMaximum size of a quilt when grouping the files (never more than the largest blob of the network).
--network <file>local networkJSON file that describes the network: RPC URL and the IDs of its packages and objects (see Contracts). For testnet, also set IOTA_RPC_URL=https://api.testnet.iota.cafe.

Examples​

# testnet
export IOTA_RPC_URL=https://api.testnet.iota.cafe

# publish (the first time) or update (afterwards) a folder for 5 epochs
node site.mjs deploy ./my-site --network testnet.json --key alice.key --epochs 5

# update a given site
node site.mjs update ./my-site <site ID> --network testnet.json --key alice.key

# list what a site contains
node site.mjs map blog.alice.iota --network testnet.json

# give a site an address with your name, and with a subname of it
node site.mjs name <site ID> alice.iota --network testnet.json --key alice.key
node site.mjs name <site ID> blog.alice.iota --network testnet.json --key alice.key
node site.mjs names --network testnet.json --key alice.key
node site.mjs unname blog.alice.iota --network testnet.json --key alice.key

# convert between the object ID and the subdomain
node site.mjs convert <site ID> --network testnet.json

# extend the blobs of a site up to the current epoch + 30
node site.mjs renew <site ID> --network testnet.json --key alice.key --epochs 30

# destroy a site and recover its deposits
node site.mjs destroy <site ID> --network testnet.json --key alice.key

When it publishes or updates, the CLI prints how many files it uploads, reuses and renews, each quilt (blob ID, files, size, cost and end epoch), the ID of the Site, its base36 form and its URL in the portal. Symbolic links in the folder are not published (they could lead outside it): the CLI lists them.

If the response of a transaction does not arrive (the connection drops), the CLI looks it up by its digest for a minute before giving up. If it still does not appear, the error gives the digest: look it up in an explorer before running the command again, or a renewal could be paid twice.

How it works​

The CLI is built on the library sites.mjs, which has no Node.js dependencies so that the app can use it in the browser too. For each publication it:

  1. reads the folder and ws-resources.json, and drops the ignored files;
  2. computes the headers and the SHA-256 of each file;
  3. compares them with the published Site, if any, to upload only what changed (see Update, renew and destroy);
  4. groups the files to upload in quilts and registers all of them as blobs in one transaction, paying in IOTA;
  5. uploads the slivers to the storage nodes and, in a second transaction, certifies the quilts and creates or updates the Site, renews the blobs still in use and deletes the deletable blobs that are no longer used.

With nothing to upload, there is only the second transaction. Only a very large site needs more: the rest of the Site and then the deletions go in their own transactions.