Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

twitch-ucashpay

A Twitch chat bot that creates U.CASH Pay checkout links (crypto + cards) on demand. Non-custodial: the bot uses your store's publishable Cloud Token, which is safe to use straight from the browser/client, so it never holds funds or needs a server secret.

When a viewer runs !pay <amount> [currency] [title], the bot posts a pay.u.cash/embed.php link the viewer can click to pay with crypto or, if the merchant connected Stripe, by card.

Features

  • Joins one or more Twitch channels via tmi.js.
  • Responds to !pay <amount> [currency] [title] with a hosted checkout link.
  • Publishable Cloud Token only (no server secret, no custody).
  • Optional !pay help.
  • Configurable via environment variables.

Usage

!pay 5              -> pay $5 USD
!pay 5 USD          -> pay $5 USD
!pay 5 EUR          -> pay 5 EUR
!pay 10 "Coffee"    -> pay $10 USD titled "Coffee"
!pay 10 EUR "Beer"  -> pay 10 EUR titled "Beer"
"Tip me" 5 USD      -> also accepted (quoted title first)
!pay help           -> show usage

The posted link looks like:

https://pay.u.cash/embed.php?cloud=<STORE_CLOUD_TOKEN>&amount=5&currency=USD&title=Coffee&external_reference=...

Quick start

  1. Create a Twitch chat-bot account (or reuse your account) and get a chat OAuth password at https://twitchapps.com/tmi/. This is a chat token, not your account password.

  2. Install dependencies:

    npm install
  3. Configure via environment variables (or a .env file you source yourself):

    export TWITCH_BOT_USERNAME="your_bot_account"
    export TWITCH_BOT_OAUTH="oauth:xxxxxxxxxxxxxxxx"
    export TWITCH_CHANNELS="yourchannel,otherchannel"
    export UCASH_CLOUD_TOKEN="st_xxxxxxxxxxxxxxxxxxxxxxxx"
    # optional:
    export COMMAND_PREFIX="!pay"
    export DEBUG=1
  4. Run the bot:

    npm start

Environment variables

Variable Required Description
TWITCH_BOT_USERNAME yes Lowercase Twitch account the bot logs in as.
TWITCH_BOT_OAUTH yes Chat OAuth password from https://twitchapps.com/tmi/ (include the oauth: prefix).
TWITCH_CHANNELS yes Comma-separated list of channels to join (with or without #).
UCASH_CLOUD_TOKEN yes Your store's publishable Cloud Token from pay.u.cash.
COMMAND_PREFIX no Command trigger. Defaults to !pay.
DEBUG no Set to 1 for verbose tmi.js logging.

Set up your pay.u.cash account

  1. Sign up at pay.u.cash, then click the verification link in the email.
  2. Set receive addresses under Settings -> Addresses (raw address, ENS, Unstoppable Domains, or FIO).
  3. Create a store under Account -> Stores and copy its Store Cloud Token (use the store-level token, not the account-wide one).
  4. For fiat cards, connect your own Stripe under Settings -> Payment processors.

How it works (non-custodial)

The bot builds a client-side hosted pay link using the GET https://pay.u.cash/embed.php endpoint:

GET https://pay.u.cash/embed.php
  ?cloud=<STORE_CLOUD_TOKEN>
  &amount=<AMOUNT>
  &currency=<CURRENCY>      (defaults to USD)
  &title=<TITLE>
  &external_reference=<ID>
  &redirect=<URL>

The store Cloud Token is publishable (designed to be used from the browser), so embedding it in a posted chat link is safe and does not give anyone control of funds. The viewer pays you directly; the bot and U.CASH never custody the funds.

Optional server-side tracked checkout

If you want a tracked, idempotent checkout row created on the server side, call the following from a separate server route (Node 18+ has global fetch):

POST https://pay.u.cash/payment/ajax.php
Content-Type: application/x-www-form-urlencoded

function=create-transaction
&amount=<AMOUNT>
&currency_code=<CURRENCY>
&cryptocurrency_code=
&external_reference=<ID>
&title=<TITLE>
&redirect=<URL>
&cloud=<STORE_CLOUD_TOKEN>
&idempotent=1

The JSON response is { "success": true, "response": [paymentUrl, transactionId, ...] }. The payment URL is the array element that starts with http:// or https://. This endpoint is idempotent per external_reference, so retrying the same reference returns the same checkout. index.js includes a commented-out reference implementation of this call.

Limitations

  • No automatic crypto recurring billing. U.CASH Pay checkouts are one-shot payments (crypto on-chain, or card charges via your Stripe). Recurring subscriptions are not supported by this bot.
  • Rate limits / chat length. The bot clamps the title for chat safety; very long titles are truncated.
  • Moderation. Use a dedicated bot account and scope it to the channels you control or moderate.

License

MIT. See LICENSE.

About

Twitch chat bot that creates U.CASH Pay checkout links (crypto + cards). Non-custodial.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages