Developers

Onboard with an email. Keep your web3 code.

@candela/sdk is a standard @alephium/web3 SignerProvider with React bindings. Add a provider and a button, and every user who signs in has a wallet your contracts already understand.

src/deploy.ts
// Generated Ralph wrappers take any SignerProvider.
// Groupless (Danube) accounts name the contract's group.
const group = groupOfAddress(account.address)

// With a browser-extension wallet:
await Guestbook.deploy(extension, { initialFields }, group)

// With Candela, for users who signed in with email:
const { wallet } = useCandela()
await Guestbook.deploy(wallet, { initialFields }, group)

Quickstart

Live in four steps.

Everything below runs against the hosted Candela window. You never handle a key, a share or a password.

  1. 1

    Create an app in the dashboard

    Get an app ID, add your allowed origins (including http://localhost while you build) and set the name and branding users see in the Candela window.

    Open the dashboard
  2. 2

    Install the SDK

    One package for the wallet and the React bindings. @alephium/web3 is a peer you already have.

    terminal
    npm install @candela/sdk @alephium/web3
  3. 3

    Wrap your app

    CandelaProvider creates the wallet and restores the user’s session. With announce, Candela also appears in the official @alephium/web3-react connect button: tested end to end with version 3.0.5 (connect, transfer, contract deploy and call, auto-reconnect).

    src/main.tsx
    import { createRoot } from 'react-dom/client'
    import { CandelaProvider } from '@candela/sdk/react'
    import { App } from './App'
    
    const candela = {
      appId: 'app_xxxxxxxx', // from the Candela dashboard
      vaultUrl: 'https://vault.candela.example',
      apiUrl: 'https://api.candela.example',
      networkId: 'testnet',
      nodeUrl: 'https://node.testnet.alephium.org',
      appName: 'Tipjar'
    } as const
    
    createRoot(document.getElementById('root')!).render(
      <CandelaProvider config={candela} announce>
        <App />
      </CandelaProvider>
    )
  4. 4

    Add the button, use the wallet

    ConnectButton handles sign-in and shows the connected address. wallet is a SignerProvider: call it as you would any wallet.

    src/App.tsx
    import { ONE_ALPH } from '@alephium/web3'
    import { ConnectButton, useCandela } from '@candela/sdk/react'
    
    export function App() {
      const { wallet, account } = useCandela()
      if (!account) return <ConnectButton label="Sign in" />
    
      // A standard SignerProvider call: Candela shows the decoded
      // transaction in its own window before anything is signed.
      const tip = () =>
        wallet.signAndSubmitTransferTx({
          signerAddress: account.address,
          destinations: [{ address: CREATOR, attoAlphAmount: ONE_ALPH }]
        })
    
      return <button onClick={tip}>Send a tip</button>
    }

Code samples

It is just a SignerProvider.

Generated Ralph wrappers, message signing and custom sign-in buttons. Nothing here is Candela-specific except the hook.

  • Contract.deploy(signer) and Script.execute() unchanged
  • loginHint opens Candela straight on Google, X, Discord or email
  • Every rejection is a CandelaError with a stable code
src/guestbook.ts
import { stringToHex, type SignerProvider } from '@alephium/web3'
import { Guestbook, SignGuestbook } from '../artifacts/ts'

// Generated Ralph wrappers take any SignerProvider.
// Pass the Candela wallet: no Candela-specific code here.
export async function sign(
  signer: SignerProvider,
  book: string,
  text: string
) {
  const tip = 10n ** 17n // 0.1 ALPH
  return SignGuestbook.execute({
    signer,
    initialFields: {
      book: Guestbook.at(book).contractId,
      message: stringToHex(text),
      tip
    },
    attoAlphAmount: tip
  })
}

API overview

A small surface, on purpose.

Everything is exported from @candela/sdk and @candela/sdk/react.

CandelaProvider

<CandelaProvider config announce?>
config.appId
Your app id from the dashboard. The vault only serves the websites you allow for it.
config.vaultUrl
Origin of the Candela window.
config.apiUrl
Candela server: app settings and access tokens. Defaults to a local address, so set it outside local development.
config.networkId
Must match the vault’s network, or requests are refused.
config.nodeUrl
Node used for reads and by contract helpers.
config.appName
Shown next to the verified origin. Optional.
config.walletConnectProjectId
WalletConnect project id. Enables “Mobile or desktop wallet” in the connect dialog; without it that option is hidden. Optional.
config.theme
'dark', 'light' or 'auto'. Default 'dark'. Sets the default for ConnectButton and the popup-blocked dialog; 'auto' follows the system (prefers-color-scheme).
announce
Also list Candela in @alephium/web3-react. Default off.

useCandela()

const { wallet, account, status, walletType, identityVerified, connect, disconnect, getAccessToken, error } = useCandela()
wallet
The CandelaWallet, a SignerProvider.
account
Connected account, restored on reload. Undefined when signed out.
status
disconnected, connecting or connected.
connect(opts?)
Opens the connect dialog: Candela sign-in, the Alephium extension, WalletConnect. With loginHint, opens Candela directly. Call it from a click.
walletType
'candela', 'extension', 'walletconnect' or 'desktop'. Undefined when signed out.
identityVerified
true when getAccessToken() can work: always after a Candela sign-in, and after the user of an external wallet signed the Sign in with Alephium message. If they declined, the wallet still signs transactions; verifyIdentity() asks again.
disconnect()
Forgets the connection in this dApp.
getAccessToken()
Short-lived token for your backend, or null: verify it with @candela/sdk/server.

ConnectButton

<ConnectButton label? loginHint? addressGroup? theme? />
label
Button text when signed out. Default Sign in.
loginHint
google, x, discord or email.
addressGroup
Optional, for compatibility: the groupless address works in every group.
theme
'dark', 'light' or 'auto'. Default 'dark', or config.theme when set. 'auto' follows the system (prefers-color-scheme).
className
And style, to fit your design.

CandelaWallet

class CandelaWallet extends InteractiveSignerProvider
Sign and submit
signAndSubmitTransferTx, signAndSubmitDeployContractTx, signAndSubmitExecuteScriptTx, signAndSubmitUnsignedTx, signAndSubmitChainedTx
Sign only
signTransferTx, signDeployContractTx, signExecuteScriptTx, signChainedTx, signUnsignedTx, signMessage
Lifecycle
connect (dialog), enable (Candela directly), autoConnect (restores any wallet type), subscribe, disconnect
Wallet
walletType, identityVerified, verifyIdentity(), getAccessToken(). Sign-only methods are Candela-only: external wallets sign and submit.

Errors

Every rejection is a CandelaError; check it with isCandelaError(e) and branch on e.code:

  • USER_REJECTED
  • NOT_CONNECTED
  • NETWORK_MISMATCH
  • POPUP_BLOCKED
  • POPUP_CLOSED
  • UNKNOWN_APP
  • ORIGIN_NOT_ALLOWED
  • UNSUPPORTED
  • INVALID_REQUEST
  • INTERNAL

Server-side verification

Call getAccessToken() in the browser and send the token to your backend. There, createCandelaVerifier from @candela/sdk/server checks it against Candela’s public keys and gives you the user id and wallet address, scoped to your app.

Tokens are signed JWTs with your app id as audience; a token issued for another app is refused.

Good to know

How Candela behaves in your app.

Open from a click

Candela opens a window, so browsers need a user gesture. Call wallet methods straight from the click handler, with no await before them. If a popup is blocked, the SDK shows a “Continue in Candela” prompt.

One network per app

The SDK and the vault both refuse a mismatched networkId, including inside the transaction bytes.

Groupless addresses

Accounts are Danube groupless addresses (key type gl-secp256k1): one address that works everywhere on Alephium. An addressGroup option is accepted for compatibility and is always satisfied.

Bring your own wallet

The connect dialog also offers the Alephium extension and WalletConnect (mobile and desktop wallets). Turn each option on or off per app in the dashboard: Candela sign-in, extension, WalletConnect. Users of an external wallet sign one free message (Sign in with Alephium) so getAccessToken() works the same for everyone.

Readable contract calls

Add your compiled contract artifacts (artifacts/*.ral.json) in the dashboard and the confirmation screen shows Guestbook.sign with its argument names instead of a function number. Candela only uses a description for a contract whose code on chain is the one you compiled, reads the values from the transaction itself, and tells users that the names are yours. Only names and types are uploaded.

Allowed origins

Users approve each origin once. Requests from an origin they have not approved are refused with NOT_CONNECTED.

Your first wallet is one sign-in away.

Create an app in the dashboard, add two components, and your Alephium dApp onboards people with an email. Free during beta.