SELFHOLD / FOR DEVELOPERS Guide pages ↓
Selfhold for developers
Let people connect their Selfhold account to your site, approve writes to a Lattice chain and sign messages. Your site never holds a key, and every write is approved by the person.
- No API key, dashboard or sign-up. Load one script and call it.
- Works on phones. Where Selfhold for Chrome isn't installed, Selfhold's window opens over your page. The account is a passkey, so there's nothing for the person to install.
- No coins needed, if your app runs a fee sponsor: the person's device pays the network fee with work. See Pay fees with work.
Quickstart: connect and sign, in five minutes
You'll make a page that connects a Selfhold account and signs a message. It needs no chain and no coins.
You need: a browser with passkeys (Chrome, Safari, Edge or Firefox, current versions), and any way to serve a folder on localhost.
1. Save this page as index.html
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>Selfhold quickstart</title>
<button id="connect">Connect</button>
<button id="sign" disabled>Sign a message</button>
<p id="out"></p>
<script type="module">
import { selfhold } from "https://wallet.selfhold.app/v1/selfhold.js";
const wallet = selfhold();
const out = document.querySelector("#out");
const sign = document.querySelector("#sign");
// Each call opens Selfhold's window, so each runs first in a click.
document.querySelector("#connect").onclick = async () => {
try {
const address = await wallet.connect();
out.textContent = `Connected: ${address}`;
sign.disabled = false;
} catch (error) {
out.textContent = error.message; // written for the person, so show it as it is
}
};
sign.onclick = async () => {
try {
const { signature } = await wallet.signMessage({ text: "Hello from my site" });
out.textContent = `Signed: ${signature.slice(0, 24)}…`;
} catch (error) {
out.textContent = error.message;
}
};
</script>
2. Serve it on localhost
Selfhold's window takes calls from https sites and from your own computer. From the folder with index.html, run:
python3 -m http.server 8000
Then open http://localhost:8000. Opening the file directly (file://) doesn't work: the window needs a page with an origin.
3. Press Connect
Selfhold's window opens. It says http://localhost:8000 (a site on this computer) asks for your Selfhold account.
Press Create an account, make the passkey when your browser asks, then press Connect.
Your page shows:
Connected: bafyreiesev7co6ott6lg4tqtfxroi5vhog3dsqh7ftzh453oagcwxunkfa
That's your account's address. Yours will differ.
If Selfhold for Chrome is installed in this browser, its own window asks instead, for its own account. wallet.kind says which one your page is using.
4. Press Sign a message
The window shows the text and your site. Press Sign with your passkey. Your page shows:
Signed: 40cd3cab82f2bbf77b714035…
Your signature's characters will differ.
That's the whole loop: your page asked, the person approved in Selfhold, and your page got the answer. Nothing was sent to a chain.
Next steps
Ways to load it
- From Selfhold's host, as above:
https://wallet.selfhold.app/v1/selfhold.jsgets every fix in version 1. To pin one release instead, see Versions and changes. - A copy in your site: download a release and serve it yourself. It's one small, readable file with no dependencies.
Source, MIT licensed: github.com/adalinxx/selfhold-wallet ↗
Something wrong or missing here? Report it on GitHub ↗