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

# Add a donate button

> Take a donation from your user's wallet and send it to a charity or campaign

A donate button does four things: it knows who the money is for, it knows which contract to call
on the donor's chain, it tells the donor the fee, and it sends one transaction. Donate does the
rest. The API calls are on `https://api.donate.gg/api/v2`.

## 1. Decide who the money is for

Let the person choose a beneficiary, or choose one yourself. Either way you end with a `type` and
an `id`. [Build a beneficiary picker](https://docs.donate.gg/guides/beneficiary-picker.md) covers the search.

Then create a config for that choice on your server. A config is the thing a donation is made
against.

```bash theme={null}
curl -X POST "https://api.donate.gg/api/v2/configs" \
  -H "donate-api-key: $DONATE_API_KEY" \
  -H "content-type: application/json" \
  -d '{"beneficiaries":[{"type":"charity","id":"9b4dae4e-d8c1-4322-a594-35a4858296b2","weight":1}]}'
```

The answer has the config's id twice: `id`, the 32 bytes as `0x` hex for an EVM chain, and
`idBase58`, the same bytes for Solana. Store both. The same beneficiaries and weights always give
the same config, so create it once per choice and reuse the id for every donor: the answer is
`201` the first time and `200` after. Configs are permanent, and a donation through a config your
project created pays a 20% fee today. See [Concepts](https://docs.donate.gg/concepts.md#configs-and-weights).

## 2. Find the contract on the donor's chain

[`GET /v2/chains`](https://docs.donate.gg/api-reference/reference/chains/list) lists the chains a donation can be made
on, with the contract or program a donation calls on each.

```bash theme={null}
curl "https://api.donate.gg/api/v2/chains"
```

An example answer, with two of the chains:

```json theme={null}
{
  "items": [
    {
      "id": 101,
      "name": "Solana",
      "type": "solana",
      "donationRelay": {
        "address": "RLAYHr9TRFcKB2ubYQhspcnXiaGpaVzNQvHytt47RZu",
        "settlementChainId": 101,
        "bridge": null
      }
    },
    {
      "id": 8453,
      "name": "Base",
      "type": "evm",
      "donationRelay": {
        "address": "0x02A0d2a39732082b824a5A3D3b026C54d581DCC8",
        "settlementChainId": 101,
        "bridge": {
          "settlementCurrency": "USDC",
          "minimumAmountAtomic": "0",
          "slippageBps": 300,
          "reclaimAfterSeconds": 86400,
          "methods": ["donateNative", "donateToken", "donateTokenWithPermit"]
        }
      }
    }
  ],
  "nextCursor": null
}
```

| Field | Meaning |
| - | - |
| `id` | Chain id. EVM chains use their EIP-155 id. Solana is `101` |
| `type` | `evm` or `solana` |
| `donationRelay` | The contract or program a donation calls. `null` on a chain that has none: offer only chains where it is set |
| `donationRelay.address` | The contract or program to call. An EVM address is in checksum form |
| `donationRelay.settlementChainId` | Where the donation settles. `101` for every chain today |
| `donationRelay.bridge` | Set on a chain whose donations are carried to another chain to settle, which is every EVM chain today. `null` on Solana |
| `donationRelay.bridge.methods` | The contract methods a donation may call |
| `donationRelay.bridge.settlementCurrency` | The currency the donation arrives in on the settlement chain |
| `donationRelay.bridge.minimumAmountAtomic` | The smallest donation the bridge carries, in atomic units of the settlement currency |
| `donationRelay.bridge.slippageBps` | Swap tolerance in basis points |
| `donationRelay.bridge.reclaimAfterSeconds` | How long before an undelivered deposit can be reclaimed on the origin chain |

This list changes rarely. The answer says so with `Cache-Control: private, max-age=300`: read it
at startup and keep it for minutes, not per request.

## 3. Tell the donor the fee

A config has no fee on it. Ask for the fee that applies now, for the chain the donor pays on and
the address the donation is credited to. The address below is a placeholder nobody holds: send
the donor's wallet.

```bash theme={null}
curl "https://api.donate.gg/api/v2/configs/BN5zs4C4zce2XBL3QjqV7LTjE51822i2jX4TPQ8DjM3v/fee?chainId=101&creditedAddress=ExampLeWa11et1111111111111111111111111111111"
```

An example answer:

```json theme={null}
{ "feeBps": 2000, "evaluatedSlot": "381204455" }
```

`feeBps` is in basis points, so `2000` is 20%. The quote is an estimate and is not locked: ask
again just before the donor signs, and if the call fails, say the fee is unavailable. See
[Fees](https://docs.donate.gg/concepts.md#fees).

## 4. Send the transaction

The transaction names the config id and nothing else about the recipients.

| Argument | Solana | EVM |
| - | - | - |
| Config id | `idBase58` as a `Pubkey`, or the 32 bytes of `id` | `id` as `bytes32` |
| Amount | `amount` in the token's atomic units | `msg.value`, or the token amount |
| Tip | `tip_bps`, 0 to 10000 | `tipBps`, 0 to 10000 |
| Credited to | `credited_to` | `creditedTo` |
| Message | `message`, up to 255 bytes | `message`, up to 256 bytes |

* On Solana, call the Donation Relay program. Instructions, accounts and rent are on the
  [Solana page](https://docs.donate.gg/blockchain/solana-svm.md).
* On an EVM chain, call `donateNative`, `donateToken` or `donateTokenWithPermit` on the
  `donationRelay.address` for that chain. See [EVM](https://docs.donate.gg/blockchain/evm.md) and
  [Bridged EVM donations](https://docs.donate.gg/blockchain/donation-bridge.md).

The credited address is the address the donation is attributed to, usually the donor's wallet. It
is also the `creditedAddress` you quoted the fee for.

## 5. Tell the donor what happens next

A confirmed transaction is not a finished donation. The money is converted to USDC, batched and
then paid out, which can take a while for a small amount. Keep the transaction hash and show
progress; do not ask the donor to send again. [Track a donation](https://docs.donate.gg/guides/track-a-donation.md) shows
how.

## Runnable sequence

```bash theme={null}
export DONATE_API_KEY="your key"

# 1. Create the config once and keep its id (permanent)
curl -X POST "https://api.donate.gg/api/v2/configs" \
  -H "donate-api-key: $DONATE_API_KEY" \
  -H "content-type: application/json" \
  -d '{"beneficiaries":[{"type":"charity","id":"9b4dae4e-d8c1-4322-a594-35a4858296b2","weight":1}]}'

# 2. Chains you can donate on are the ones whose donationRelay is not null
curl "https://api.donate.gg/api/v2/chains"

# 3. Quote the fee just before the donor signs, with the donor's wallet in place of the placeholder
curl "https://api.donate.gg/api/v2/configs/BN5zs4C4zce2XBL3QjqV7LTjE51822i2jX4TPQ8DjM3v/fee?chainId=101&creditedAddress=ExampLeWa11et1111111111111111111111111111111"

# 4. The donor's wallet sends the transaction on-chain.

# 5. Show recent donations to the beneficiary
curl "https://api.donate.gg/api/v2/charities/9b4dae4e-d8c1-4322-a594-35a4858296b2/donations?limit=5"
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.