RewardyDevelopers

Rewardy Connectv0.1.0

Sign in with Rewardy

Let people connect Rewardy Wallet and sign in to your site with a single approval in the app. No registration and no API key.

npm install @chainwith/rewardy-connect

Try it

Scan with the Rewardy app and approve. It uses the same button and relay server your site will use.

Theme
Size

The demo shows the address only and stores nothing.

How it works

The SDK draws the button and the QR window, and your server checks one standard EIP-4361 signature.

  1. 1

    Click the button

    A window with a QR code opens on your site. On a phone, "Open Rewardy app" comes first.

  2. 2

    Scan with Rewardy

    As soon as the app scans the code, your site shows "Approve in Rewardy". Codes last 2 minutes and renew in place.

  3. 3

    Approve once

    The wallet connects and signs the sign-in message in the same approval. Your server verifies it and starts the session.

Inside the Rewardy in-app browser there is no QR code: your site uses the app's wallet directly.

Quickstart

Three steps: install the SDK, add the button, and verify the signature on your server.

1

Install

The package works with any framework: plain HTML, React, Next.js, Vue or Svelte. TypeScript types are included.

npm install @chainwith/rewardy-connect
2

Add the button

The button fetches a nonce from your server, opens the QR window and hands you the signed message.

import { RewardyClient, mountSignInButton } from '@chainwith/rewardy-connect';

// Create one client per page and reuse it.
const client = new RewardyClient();

mountSignInButton(document.querySelector('#rewardy-login'), {
  client,
  statement: 'Sign in to Example',
  connect: { chains: ['eip155:1'] },
  getNonce: async () => (await post('/api/auth/nonce')).nonce,
  onSignIn: async ({ message, signature }) => {
    await post('/api/auth/verify', { message, signature });
    location.reload();
  },
  onError: (error) => {
    if (error?.code !== 4001) console.error(error); // 4001: the user closed it
  },
});

Keep your own button? Call client.signIn() on click:

const { nonce } = await post('/api/auth/nonce');
const { message, signature } = await client.signIn({
  nonce,
  statement: 'Sign in to Example',
  connect: { chains: ['eip155:1'] },
});
await post('/api/auth/verify', { message, signature });
3

Verify on your server

Issue a one-time nonce, then check the message and signature. verifySignIn throws when any check fails.

import { createSignInNonce, verifySignIn } from '@chainwith/rewardy-connect/server';

app.post('/api/auth/nonce', (req, res) => {
  req.session.nonce = createSignInNonce();
  res.json({ nonce: req.session.nonce });
});

app.post('/api/auth/verify', async (req, res) => {
  // Remove the nonce before checking so it can never be used twice.
  const nonce = req.session.nonce;
  delete req.session.nonce;
  try {
    const { address } = await verifySignIn({
      message: req.body.message,
      signature: req.body.signature,
      origin: 'https://example.com', // your site's exact origin
      nonce,
      chainIds: [1],
    });
    req.session.address = address;
    res.json({ address });
  } catch {
    res.status(401).json({ error: 'invalid sign-in' });
  }
});
  • Not on Node.js? Verify with any EIP-4361 (Sign-In with Ethereum) library. The domain and URI are always your site's origin.
  • Keep the statement to ASCII text so strict EIP-4361 libraries accept it.

Customize

The standard UI follows Rewardy's design. Change the look and text without building your own.

OptionValuesWhat it changes
themegradient · dark · lightButton color
sizesm · md · lgButton height (36, 48, 56 px)
labelany textButton text
modal.localeen · koWindow language (English by default)
modal.themelight · dark · autoWindow color scheme
modal.textany sentenceReplace any window text, for example in Japanese
const client = new RewardyClient({
  modal: { locale: 'en', theme: 'auto', text: { signInTitle: 'Sign in to Example' } },
});

mountSignInButton(target, {
  client,
  theme: 'dark',   // 'gradient' | 'dark' | 'light'
  size: 'lg',      // 'sm' | 'md' | 'lg'
  label: 'Continue with Rewardy',
  // ...getNonce, onSignIn
});

Prefer your own window? Set modal: false and draw the connection link from onDisplayUri.

Access and limits

Start without registering. Register later if you want your site shown as verified.

Public

Default
  • No project ID, secret or registration
  • Any exact https origin; http sites cannot connect
  • The app shows your domain as unverified and asks the user to confirm
  • Up to 100 QR codes per minute per site and 20 per minute per IP address

Registered partner

On request
  • The app shows your site as verified
  • One-tap sign-in from Rewardy in-app banners
  • Adds one ticket endpoint to your server; the sign-in code stays the same
  • Higher limits on request
Contact us to register →

Testing

Test with the Rewardy app on your https staging site. For automated tests, a script can stand in for the app.

  1. Click your sign-in button and right-click "Open on this device" in the QR window to copy the link.
  2. Run the script below with the link. It approves the connection and the sign-in automatically.
Test wallet script (Node.js 20 or later)
// test-wallet.mjs - testing only. Signs with a new random key on every run.
// npm install @chainwith/rewardy-connect viem
// node test-wallet.mjs '<connection link>'
import { RewardyWalletSession } from '@chainwith/rewardy-connect/wallet';
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts';

const account = privateKeyToAccount(generatePrivateKey());

await RewardyWalletSession.accept(process.argv[2], {
  trustedRelays: ['https://connect-api.rewardywallet.com'],
  allowUnverifiedOrigins: true,
  signIn: 'any',
  signer: {
    getAccounts: async () => [account.address],
    personalSign: ({ message }) => account.signMessage({ message: { raw: message } }),
    signTypedData: ({ typedData }) => {
      const { EIP712Domain, ...types } = typedData.types;
      return account.signTypedData({ ...typedData, types });
    },
    sendTransaction: async () => {
      throw new Error('The test wallet does not send transactions');
    },
  },
  approveConnection: async (meta) => ({
    grant: { accounts: [account.address], chain: meta.permissions.chains[0], permissions: meta.permissions },
    signIn: true,
  }),
  approveRequest: async (request) => request.method !== 'eth_sendTransaction',
});
console.log('Connected as', account.address);

Errors

CodeMeaningWhat to do
4001The user closed the window or rejected in the appShow nothing and re-enable the button
4100The signature or permissions do not match the requestAsk the user to sign in again
4900The connection droppedAsk the user to sign in again
-32002A sign-in is already in progressWait for it to finish

Support

Questions, partner registration or higher limits:

develop@rewardywallet.com