# Device states, earnings and payouts

Calls go to https://supply.coronium.ai, signed in as in [enrolment](/guides/device-enrol.md).

## Steps

1. Read the devices once a minute until the new one is measured.

```sh
umask 077
SUPPLY=${SUPPLY:-https://supply.coronium.ai}
cd "${CORONIUM_DIR:-$HOME/coronium}" || exit
curl -sS -b coronium.cookies "$SUPPLY/app/api/devices" | jq -c 'if .code then {code, cause, fix} else .devices[] | {deviceId, status, state, reason} end'
```

Expect: `online` once the agent connects. Then act on `state` and `reason`:

| Reads | Means | Do |
|---|---|---|
| `status` `offline` | the agent is not connected | unless you stopped it, its log says why: [troubleshooting](/guides/device-troubleshoot.md) |
| `new`, `not_measured` | connected, not measured yet | read again a minute later |
| `withheld`, `unclassified_asn` | the network is not classified yet | nothing: leave it running, tell your person, do not enrol again |
| `withheld`, `class_not_sold` | a network Coronium does not sell, such as a data centre | stop it: it earns nothing. Do not enrol again from this network |
| `withheld`, `same_exit` | an earlier residential device, of any account, exits from this address | move it to a connection of its own, or stop it |
| `withheld`, `exit_unverified` or `exit_changed` | three measurements in a row failed, or the country changed | keep it running: it is measured again |
| `withheld`, `supplier_blocked` | the operator blocked the account | tell your person |
| `admitted` | carries buyer traffic as fallback supply | done |
| `established` | carries traffic first, after the operator promoted it on a clean history | done |
| `paused`, `private` | the account's own choice | nothing, unless your person asks |
| `withdrawn` | permanent | a new enrolment, if your person wants one |

`requests`, `bytesUp` and `bytesDown` include Coronium's own exit measurements, which earn nothing. Safe to repeat: yes.

`health` says whether a device still carries traffic: [device health](/guides/device-health.md).

2. Read the statement.

```sh
umask 077
SUPPLY=${SUPPLY:-https://supply.coronium.ai}
cd "${CORONIUM_DIR:-$HOME/coronium}" || exit
curl -sS -b coronium.cookies "$SUPPLY/app/api/earnings" | jq '{earned, held, available, requested, paid, payoutMinimumUsdMicros, terms}'
```

Expect: the totals and `terms`; [the statement and a payout](/guides/device-payouts.md) explains each field. Safe to repeat: yes.

<!-- facts:begin payout.day -->
Payouts are paid by hand on the 6th of each month, for requests received before it; later ones the next month.
<!-- facts:end payout.day -->

3. Ask for a payout, only with your person's word: [the block](/guides/device-payouts.md).

## What a device refuses

<!-- facts:begin part.device-refuses -->
Beside the ranges the protocol forbids, a device never dials what its system shows of its own network: its own addresses as its interfaces show them, its default gateway (the home router), any address on the links of its interfaces, and any of these behind a NAT64 prefix that the protocol or its resolver names. Such a target is answered `target_blocked`. What the system does not show is not refused yet: the public address of a router in front of the device, which the device does not know, and a target behind a NAT64 prefix that only the router announces. When the device cannot tell whether an IPv6 target is safe (it cannot read its interfaces, its resolver failed on `ipv4only.arpa` or synthesizes in a form it cannot read, or an IPv6 address of the device has no on-link prefix it can read), it carries IPv4 only, answers a target with no IPv4 address `unreachable`, and its log says why. Nothing to do.
<!-- facts:end part.device-refuses -->

## Stop and withdraw

Stopping the agent stops sharing; withdrawal is for good. [Update, stop, remove and withdraw](/guides/device-lifecycle.md) has the one answer for each. `reason` says who withdrew:

<!-- facts:begin withdrawn.reasons -->
- `user`: the device's own secret: in an app, its user's no
- `account`: the account, signed in
- `token`: a revoke of the token that enrolled it
- `fleet`: Coronium, for the whole account
- `owner`: Coronium, for this device, or an older withdrawal
<!-- facts:end withdrawn.reasons -->
