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

# Pay USDC from the Pot

> One transaction on Base, Ethereum or Arc that pays USDC from the Pot to one recipient and returns the amount the recipient received.

The program pays `amount` of USDC from the Pot to `to`, reads the recipient's balance before and after the transfer, and returns the difference. It reverts when the Pot holds less than `amount` or when the recipient's balance rises by anything other than `amount`.

**Target chains:** Base, Ethereum and Arc. The same source compiles for all three; the recorded simulation uses a Base fork.

## Prerequisites

Install the [Sauce CLI](https://docs.eco.com/sauce-sdk/installation.md) to compile and simulate. To send the transaction, configure a wallet with funds for gas and the Kitchen fee. Provide the required tokens in your Pot once it is deployed, or through `--fund`; see [funding](https://docs.eco.com/sauce-sdk/cli/funding.md).

## Program

`pot` is the Pot the program runs on, available without declaring it ([Names](https://docs.eco.com/sauce/names.md#balances)).

```ts pay.sauce.ts theme={null}
// Pays `amount` of USDC from the Pot to `to`, measures what `to` received, and returns it. The
// cook reverts, and nothing moves, when `amount` or `to` is zero, when the Pot holds less USDC
// than `amount`, or when the balance of `to` rises by a different amount. The same file compiles
// for Base, Ethereum and Arc: on each, `pot.USDC` is the Pot's balance of that chain's USDC token.
//
//   sauce simulate pay.sauce.ts --chain <chain> --owner <address> \
//     --assume-balance USDC:<amount>n --args <to> <amount>
//   sauce run pay.sauce.ts --chain <chain> --wallet <name> --args <to> <amount>
//
//   to: Address       who is paid, an address on the chain the program runs on
//   amount: Uint256   the USDC to pay, in its base units (6 decimals): 1000000 is 1 USDC
//
// On Base, pay 1 USDC to <recipient> from a Pot that holds at least 1 USDC:
//
//   sauce run pay.sauce.ts --chain base --wallet me \
//     --args <recipient> 1000000
function main(to: Address, amount: Uint256): Uint256 {
  require(amount > 0, "amount is zero");
  require(to != 0, "no recipient");
  require(pot.USDC >= amount, "not enough USDC in the Pot");

  const before = USDC.balanceOf(to);
  USDC.transfer(to, amount);
  const received = USDC.balanceOf(to) - before;
  require(received == amount, "recipient received a different amount");

  return received;
}
```

## How it works

* `pot.USDC` is the Pot's balance of the chain's `USDC` token, and `USDC.balanceOf(to)` the recipient's. On Arc, where USDC is also the native coin, both read the six-decimal token; `pot.balance` would read the 18-decimal coin.
* `received` is measured at the recipient, not assumed from the transfer. The `require(received == amount, ...)` line reverts the cook for a token that takes a fee on transfer.
* `main` returns `Uint256`, so `sauce simulate` decodes the return value and prints it as `main returns Uint256: ...`.
* Each `require` carries a reason. A reverted simulation prints that reason, which is what `--expect-revert` matches.

## Run the example

**1. Compile**

```bash theme={null}
sauce compile pay.sauce.ts --chain base
```

Replace `base` with `ethereum` or `arc`. Each compile is 433 bytes, but the bytecode differs, because each carries its chain's USDC address.

**2. Simulate**

```bash theme={null}
sauce simulate pay.sauce.ts --chain base --owner <your-address> \
  --assume-balance USDC:5 --args <recipient> 1000000
```

`--assume-balance USDC:5` gives the Pot 5 USDC for this simulation only, by state override. The output lists each transfer and each address's net change.

**3. Send**

```bash theme={null}
sauce run pay.sauce.ts --chain base --wallet <name> \
  --fund USDC:1 --args <recipient> 1000000
```

`sauce tx` prints the unsigned transaction instead, for your own signer:

```bash theme={null}
sauce tx pay.sauce.ts --chain base --owner <your-address> \
  --fund USDC:1 --args <recipient> 1000000
```

## Simulation result

Simulated on a local fork of Base at block 53122821 with the current contracts, with the command above, paying 1 USDC to `0x7099…79C8`. Nothing was signed or sent.

```text theme={null}
The cook succeeds from 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266: gas used 117483 for the cook, after the Pot's deploy (1. below), returns 0x00000000000000000000000000000000000000000000000000000000000f4240
main returns Uint256: 1000000
Left in the Pot, not in the owner's wallet:
  4 USDC (it held 5 USDC before)
...
  2. the cook, from the owner 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266, gas used 117483
Assumed for this simulation only, by state override:
  the Pot holds 5 USDC: --assume-balance (its balance word 0xcb5320fe60abad81834e0e994e8a7a8eb33991917b05a5c0498fe1c0373a2087: Solidity mapping at slot 9)
What moved, in order:
...
  [3] Pot                -> 0x7099…79C8          1 USDC
Net balance changes:
  0xDcFCc75A3C9a0EC798CAf81B6C84D4c5d5988c49 (the Pot): -1 USDC
  0x70997970C51812dc3A010C7d01b50e0d17dc79C8: +1 USDC
  0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 (owner): -0.00000374478538635 ETH
```

The Pot did not exist yet, so the simulation deployed it first. The recipient's balance rose by exactly 1 USDC, which `main` returned as `1000000`.

On the same fork, the guard, with a Pot holding 0.5 USDC:

```bash theme={null}
sauce simulate pay.sauce.ts --chain base --owner <your-address> \
  --assume-balance USDC:0.5 --args <recipient> 1000000 \
  --expect-revert "not enough USDC in the Pot"
```

```text theme={null}
As expected, the cook reverts: the program threw "not enough USDC in the Pot"
The cook reverts: the program threw "not enough USDC in the Pot"
```

The guard stopped the cook before any USDC moved, and `--expect-revert` exited 0 because the reason matched.

## Next steps

* [Pay a list of recipients](https://docs.eco.com/quickstarts/sauce/pay-list.md): the same payment in a loop, with a cap on the total
* [Payroll by weight](https://docs.eco.com/quickstarts/sauce/payroll-by-weight.md): split one budget by weight
* [Native USDC payment on Arc](https://docs.eco.com/quickstarts/sauce/arc-native-payment.md): pay as native value on Arc
* [`sauce simulate`](https://docs.eco.com/sauce-sdk/cli/simulate), [`sauce run`](https://docs.eco.com/sauce-sdk/cli/run), [Names](https://docs.eco.com/sauce/names.md)


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