VIZ.cx
← Learn

Onboard users with invites

10 minintermediate

Invites are how you bring people onto VIZ with zero friction: no exchange, no pre-existing account, no fee paid by the newcomer. You fund an invite, hand over a secret, and the recipient turns it into a live, capitalized account. It's one of the best reasons to build a product on VIZ.

The flow has two halves: you create a funded invite, then redeem it into a named account. The invite's private key is the claim secret that ties the two together.

Step 1 — Install the SDK

npm install @viz-cx/core

Step 2 — Create a funded invite

Generate a throwaway keypair, then broadcast create_invitewith its public key and some VIZ. That balance becomes the new account's starting capital. Keep the private key — it's the secret your user will redeem.

import { createClient, keys } from '@viz-cx/core'

// A signing client for the account that funds the invite.
const client = createClient({
  account: 'alice',
  activeKey: process.env.VIZ_ACTIVE_KEY!,
  endpoint: 'https://node.viz.cx',
})

// 1. Generate a throwaway keypair for the invite itself.
const invite = keys.generate()   // { wif, pub }

// 2. Create the invite on-chain, pre-funded with VIZ.
//    'creator' is implicit (the client's account).
await client.createInvite({
  balance: '5.000 VIZ',          // becomes the new account's starting capital
  inviteKey: invite.pub,
})

// The invite's PRIVATE key is the claim secret. Hand it to your
// user however you like — a link, a QR code, an email.
console.log('Claim secret:', invite.wif)

Step 3 — Redeem it into an account

Generate the new account's keypair, then submit invite_registrationwith the chosen name, the invite secret, and the new public key. The newcomer can't sign yet, so your service is the initiator.

import { createClient, keys } from '@viz-cx/core'

// Your service submits the registration on the user's behalf —
// the user has no account yet, so they can't sign anything.
const service = createClient({
  account: 'alice',
  activeKey: process.env.VIZ_ACTIVE_KEY!,
  endpoint: 'https://node.viz.cx',
})

// 3. Generate the NEW account's keypair. This single key controls
//    all of the account's authorities — this is what the user keeps.
const account = keys.generate()  // { wif, pub }

// 4. Redeem the invite secret to create and fund the account.
await service.inviteRegistration({
  newAccountName: 'bob',
  inviteSecret: inviteWif,       // the invite's private key from step 2
  newAccountKey: account.pub,
})

console.log('bob is live. Their key (keep it safe):', account.wif)

Optional — Password-derived keys

If you'd rather your users remember a password than store a raw WIF, derive a keyset with keys.fromPassword and register the public regular key. They can regenerate the same keys from the password later.

// Prefer a memorable master password over a raw key?
// Derive a keyset, then register with the regular public key.
const ks = keys.fromPassword('bob', userMasterPassword)  // { owner, active, regular, memo }
await service.inviteRegistration({
  newAccountName: 'bob',
  inviteSecret: inviteWif,
  newAccountKey: keys.toPublic(ks.regular),
})

Whoever holds account.wif (or the master password) controls the account — deliver it over a secure channel and never log it in production.