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

# Deliver your own payment

> Ask for authorized fulfillment, read the signed transfer from the payment status, and send it to the recipient without using a settlement operator.

With [authorized fulfillment](https://docs.atum.xyz/get-started/concepts/authorized-fulfillment.md), the settlement operator signs a transfer of its own tokens to your recipient and you submit it. This page shows the three changes from an ordinary payment: what you add to the request, where the signed transfer appears, and the transaction you send.

Read [Authorized fulfillment](https://docs.atum.xyz/get-started/concepts/authorized-fulfillment.md) first to understand the pros and cons, who does what, and which chains and tokens are supported.

## Before you start

* A payment you can already send. See [Prepare a payment](https://docs.atum.xyz/get-started/prepare-a-payment.md).
* A destination token on the EIP-3009 list for authorized fulfillment, on an EVM chain. See [Where it works](https://docs.atum.xyz/get-started/concepts/authorized-fulfillment.md#where-it-works).
* An account on the destination chain with enough native token for gas. You send the delivery transaction, so you pay its gas.
* A delivery deadline with room for your own transaction. See [Choosing a delivery deadline](https://docs.atum.xyz/get-started/concepts/deadlines.md#choosing-a-delivery-deadline).

## 1. Ask for authorized fulfillment

Add `executor` to the payment request. The settlement operator takes the deposit and reserves the funds; you deliver.

```json theme={"theme":"github-dark"}
"executor": { "deposit": "settler", "reserve": "settler", "fulfill": "originator" }
```

Always name the FulfillmentProxy yourself: set the request's `fulfillment_proxy` to the one on [Contract addresses](https://docs.atum.xyz/get-started/reference/contract-addresses.md#authorized-fulfillment). `/v1/defaults` does not say whether the proxy it returns supports authorized fulfillment.

> [!WARNING]
>
> The gateway does not check that the FulfillmentProxy supports authorized fulfillment. With one that does not, the settlement operator can take your deposit and then cannot authorize your delivery, and the payment is refunded only after the delivery deadline passes.

> [tab] SDK
>
> ```typescript theme={"theme":"github-dark"}
> // The testnet FulfillmentProxy from Contract addresses.
> const FULFILLMENT_PROXY = '0xd1254EF0f2bc75AD577FE48fC5CC9c3ec13B0144';
>
> const paymentRequest = await client.preparePaymentRequest({
>   depositor,
>   requestId: REQUEST_ID,
>   fulfillmentAmount: AMOUNT,
>   maxSourceAmount: MAX_SOURCE_AMOUNT,
>   sourceAsset: SOURCE_ASSET,
>   destinationAccount: destination,
>   destinationAsset: DESTINATION_ASSET,
>   executor: { deposit: 'settler', reserve: 'settler', fulfill: 'originator' },
>   resolvedDefaults: { destination: { fulfillmentProxy: FULFILLMENT_PROXY } },
>   // The 300 s default plus time for you to send the delivery transaction.
>   fulfillmentDeadlineSeconds: 900,
> });
> ```
>
> Sign and submit it as in the [SDK quickstart](https://docs.atum.xyz/get-started/start-building/build-with-the-sdk.md#4-send-your-first-payment), and keep the `payment_id`. Stop after `Submitted payment`: do not copy its `waitForStatus` call, because on this path the payment stays `pending` until you deliver, so that call would only time out.

> [tab] HTTP
>
> Add `executor` and `fulfillment_proxy` (the FulfillmentProxy from Contract addresses) to the request body before you sign it, and a `fulfillment_deadline` with room for your delivery. Field reference: [Submit payment](https://docs.atum.xyz/api-reference/payment-gateway/submit-payment.md).

The gateway refuses a destination token that is not on the list for authorized fulfillment. See [Where it works](https://docs.atum.xyz/get-started/concepts/authorized-fulfillment.md#where-it-works).

## 2. Wait for the signed transfer

Once your deposit is confirmed and the settlement operator has authorized your delivery, the status response carries `fulfillment_authorization`. Poll the status as in [After submission](https://docs.atum.xyz/get-started/after-submission.md#track-a-payment) until that field appears; the script below does this. Until you deliver, the payment stays `pending` and has no `transactions.fulfillment`.

`fulfillment_authorization` is a signed document from the settlement operator. Keep it exactly as you received it. The two parts you need are inside `authorization`:

| Field | What it is |
| - | - |
| `authorization.message_prehash` | The transfer, as EIP-712 typed data in a JSON string. Its `message` has `from`, `to`, `value`, `validAfter`, `validBefore` and `nonce`; its `domain.verifyingContract` is the destination token. |
| `authorization.signature` | The settlement operator's signature over that transfer. |

Before you send anything, check that the transfer is the one you asked for: `to` is your recipient, `value` is your `fulfillment_amount`, and `domain.verifyingContract` and `domain.chainId` are your destination token and chain.

Full shape: [Get payment status](https://docs.atum.xyz/api-reference/payment-gateway/get-payment-status.md).

## 3. Send the transfer

Call `transferWithAuthorization` on the destination token with the signed values, before `validBefore`.

```typescript title="deliver.ts" theme={"theme":"github-dark"}
import { ethers } from 'ethers';

const GATEWAY_URL = 'https://payment-gw.production-testnet.atum.xyz';
const PAYMENT_ID = process.env.PAYMENT_ID;
const RECIPIENT = process.env.RECEIVER;
const AMOUNT = '10000'; // the payment request's fulfillmentAmount
// The payment request's destinationAsset, as in the SDK quickstart.
const DESTINATION_ASSET = 'eip155:11142220/erc20:0x01C5C0122039549AD1493B8220cABEdD739BC44E';
const [destinationChain, TOKEN] = DESTINATION_ASSET.split('/erc20:');
const CHAIN_ID = destinationChain.split(':')[1];
const PRIVATE_KEY = process.env.PRIVATE_KEY;
const DESTINATION_RPC_URL = process.env.DESTINATION_RPC_URL;

async function main() {
  if (!PAYMENT_ID || !RECIPIENT || !PRIVATE_KEY || !DESTINATION_RPC_URL) {
    throw new Error('Set PAYMENT_ID, RECEIVER, PRIVATE_KEY and DESTINATION_RPC_URL');
  }

  // Poll until the settlement operator has authorized the delivery.
  let fa;
  for (let i = 0; i < 30 && !fa; i++) {
    const res = await fetch(`${GATEWAY_URL}/v1/payments/${PAYMENT_ID}/status`);
    fa = (await res.json()).fulfillment_authorization;
    if (!fa) await new Promise((resolve) => setTimeout(resolve, 2000));
  }
  if (!fa) throw new Error('not authorized yet: run this again');

  const typed = JSON.parse(fa.authorization.message_prehash);
  const { from, to, value, validAfter, validBefore, nonce } = typed.message;
  const { v, r, s } = ethers.Signature.from(fa.authorization.signature);

  // Check before sending.
  if (to.toLowerCase() !== RECIPIENT.toLowerCase()) throw new Error('unexpected recipient');
  if (value !== AMOUNT) throw new Error('unexpected amount');
  if (typed.domain.verifyingContract.toLowerCase() !== TOKEN.toLowerCase()) throw new Error('unexpected token');
  if (String(typed.domain.chainId) !== CHAIN_ID) throw new Error('unexpected chain');
  // The token refuses the transfer after validBefore (unix seconds).
  if (Number(validBefore) < Math.floor(Date.now() / 1000) + 60) {
    throw new Error('validBefore is too close or already passed: the token would refuse the transfer');
  }

  // The RPC must serve the destination chain. On another chain the token address
  // usually has no code, and the call would succeed without delivering anything.
  const provider = new ethers.JsonRpcProvider(DESTINATION_RPC_URL);
  const network = await provider.getNetwork();
  if (network.chainId !== BigInt(CHAIN_ID)) {
    throw new Error(`DESTINATION_RPC_URL serves chain ${network.chainId}, not ${CHAIN_ID}`);
  }

  // Any account can submit the transfer; it pays the gas.
  const wallet = new ethers.Wallet(PRIVATE_KEY, provider);
  const token = new ethers.Contract(
    typed.domain.verifyingContract,
    [
      'function transferWithAuthorization(address from, address to, uint256 value, uint256 validAfter, uint256 validBefore, bytes32 nonce, uint8 v, bytes32 r, bytes32 s)',
      'function authorizationState(address authorizer, bytes32 nonce) view returns (bool)',
    ],
    wallet,
  );

  // The status is public, so someone else may have submitted this transfer already.
  if (await token.authorizationState(from, nonce)) {
    console.log('This transfer was already submitted. Keep following the status.');
    return;
  }

  const tx = await token.transferWithAuthorization(from, to, value, validAfter, validBefore, nonce, v, r, s);
  console.log(`Delivery sent: ${tx.hash}`);
  await tx.wait();
}

main().catch((err) => {
  console.error(err);
  process.exit(1);
});
```

The recipient receives the tokens from the settlement operator's account. You never hold them.

## 4. Watch it complete

Keep following the status. `transactions.fulfillment` shows your transaction once it is mined. The statuses that follow are on [After submission](https://docs.atum.xyz/get-started/after-submission.md#payment-status).

If the transfer is not used before `validBefore`, the token refuses it and the payment is refunded to the payer. See [Refunds](https://docs.atum.xyz/get-started/support/refunds.md#when-a-refund-can-start).

## Next steps

| Topic | Guide |
| - | - |
| How authorized fulfillment works | [Authorized fulfillment](https://docs.atum.xyz/get-started/concepts/authorized-fulfillment.md) |
| Choosing a delivery deadline that leaves you time to deliver | [Deadlines](https://docs.atum.xyz/get-started/concepts/deadlines.md#choosing-a-delivery-deadline) |
| Track a payment | [After submission](https://docs.atum.xyz/get-started/after-submission.md) |
| FulfillmentProxy addresses | [Contract addresses](https://docs.atum.xyz/get-started/reference/contract-addresses.md#authorized-fulfillment) |


## Related topics

- [Authorized fulfillment](https://docs.atum.xyz/get-started/concepts/authorized-fulfillment.md)
- [Agentic payouts](https://docs.atum.xyz/get-started/use-cases/agentic-payouts.md)
- [Payment protocols](https://docs.atum.xyz/payment-protocols/overview.md)
- [Deadlines](https://docs.atum.xyz/get-started/concepts/deadlines.md)
- [Who owns what](https://docs.atum.xyz/get-started/support/who-owns-what.md)


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