> ## Documentation Index
> Fetch the complete documentation index at: https://docs.zbdpay.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Receiving instant Bitcoin payments with Supabase

> Learn how to receive Bitcoin using Supabase Edge Functions.

## Prerequisites

To complete this guide, you will need the following:

* [ZBD Project with a Live API key](/get-started/api-keys)
* [Supabase account](https://supabase.com/) + [Supabase CLI installed](https://supabase.com/docs/guides/cli#installation)

## 1. Create a Supabase Function

To create a Supabase Edge Function you must run the following command locally:

```bash theme={null}
supabase functions new zbd-receive
```

This will create a `/supabase/functions/zbd-receive` folder structure in your project.

## 2. Write the Edge Function

Use the code below as a starting point for your handler function. You will need to replace the `ZBD_API_KEY` with your own ZBD Project's API key.

```typescript theme={null}
import { serve } from "https://deno.land/std@0.168.0/http/server.ts"

const ZBD_API_KEY = "b7Ya3s2JZKZcXXX2Dqf8wjKTZZZRuWr8";

const zbdReceive = async (_request: Request): Promise<Response> => {
  const res = await fetch("https://api.zbdpay.com/v0/charges", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "apikey": `${ZBD_API_KEY}`,
    },
    body: JSON.stringify({
      amount: '100000', // 100 satoshis (100,000 msats) -- ~$0.03
      description: 'Money at internet speed', // What is this payment request for?
    }),
  });

  const data = await res.json();

  return new Response(JSON.stringify(data), {
    status: 200,
    headers: {
      "Content-Type": "application/json",
    },
  });
};

serve(zbdReceive);
```

## 3. Receive payment locally

To run this Supabase Edge Function locally you can spin up your Supabase instance using the following command. *You may already have this running at this stage.*

```bash theme={null}
supabase functions start
```

Then you can run the following command to start your serverless function:

```bash theme={null}
supabase functions serve zbd-receive --no-verify-jwt
```

Note that we add the `--no-verify-jwt` flag to the command to disable JWT verification. This is because we are not passing a JWT token to the function when we call it. **This is not recommended for production use.**

Supabase CLI will output a HTTP URL endpoint that you can use to test your function by issuing a POST request to that resource.

## 4. Deploying to Supabase Edge

After testing it locally, you can deploy your function to Supabase Edge using the following command. *You will need to enter your Supabase project ID to deploy.*

```bash theme={null}
supabase functions deploy zbd-receive
```

Once you deploy you will receive a URL that you can use to view that function in production on Supabase's Web Dashboard:

<Frame type="glass">
  <img src="https://mintcdn.com/zbd/9qd8gBIbihN5TscS/img/supabase-edge.png?fit=max&auto=format&n=9qd8gBIbihN5TscS&q=85&s=78583476cd2884a932d610d8febabce9" alt="Supabase Edge Functions dashboard" width="2604" height="926" data-path="img/supabase-edge.png" />
</Frame>

Opening your browser (or another HTTP client) to the URL provided by Supabase: `https://xxxxxxxxxxxxx.supabase.co/functions/v1/zbd-receive` should return a JSON response with the payment request details.

You can also test this using curl command:

```bash theme={null}
curl https://xxxxxxxxxxxxx.supabase.co/functions/v1/zbd-receive
```

You're looking for the `data.invoice.request` property in the JSON response. It starts with `lnbc1` and is the payment request anyone in the Bitcoin Lightning Network can use to pay you.

```
lnbc1u1pjdlax9pp5t7jhkd7h2wntd4f2v7xp22dknmjxp0q8nm7hfcny4p7a5mr7x3rsdp9f4hkueteypshggrfde6x2unwv46zqumsv4jkgcqzzsxqzjcsp5dsayu6m6632p28rnkeeqsr7d54amrkv6wh46yrv42gdgca8xl8gs9qyyssqgj2zrkax733rzulfkzc5mqsr8fpwrva82stpa7e0frw32722trv37jlq8mvlqfp8y75lr6mz63zd7qnxar8hhsehuy22pvfq6wjxwqqqa60lx3
```

<Info>Charges and payment requests are usually shown to users as QR codes that can be scanned by mobile apps (e.g. [ZBD](https://zbd.one/download)). Read [Callbacks](/payments/api/callbacks) to understand how to receive updates about your payment asynchronously.</Info>

## 5. Try it yourself

You can now begin receiving instant Bitcoin payments on the edge with Supabase + ZBD!

<CardGroup cols={1}>
  <Card title="Supabase Edge Functions Example" icon="github" color="#000000" href="https://github.com/zebedeeio/zbd-supabase-edge-functions-example">
    See the full source code.
  </Card>
</CardGroup>
