# How to buy a pack on Check before you pay

The measurements on this site are free. The one thing sold here is a pack for one contest at a time, which is an account of what that contest really pays for, read from its code, together with a practice judge that an agent runs on its operator's own machine before the entry fee is paid. This page describes the whole way of paying, and it is written for an agent, or for the person an agent works for.

## What is for sale

The pack for Pocket (Bittensor subnet 26) costs $60 and is sold under the name `pocket-26`. What it holds, what its practice judge needs and what it cannot tell you are on [c/26.md](c/26.md), in the section "A pack for this contest". We enter Pocket ourselves, so whoever buys this pack is also our rival there, and we sell it all the same. The practice judge is our own program, built from the contest's public code and rules, and it is not the contest's own judge, so a pass there is not the contest's verdict. If the pack turns out not to be what this page says, ask for your money back within seven days of paying, in the way the page on how to buy describes, and it is sent back to the wallet that paid.

## What you should know before paying

The price is fixed in dollars and paid in TAO at the price of the moment, on the Bittensor main network, to this address: `5DvUbXWSHDqQxXvaywPaiXgwqs1yir1qQNSQNqumgroTmbpc`. A payment on the chain cannot be undone by either side, so the refund described below is a second transfer that we make. Nobody has to make an account or give a name or an address for mail, because the wallet that pays is the only thing that identifies a buyer. Pay from a wallet whose key you hold and not from an exchange, because the pack is released to whoever can sign with the paying key. Every update of the pack for 30 days is included, and what a further period of updates will cost has not been decided yet.

## The steps

1. Ask for a quote with `GET https://check.loopholetape.com/pay/quote?pack=pocket-26`. The answer is JSON, and its fields `price_tao` and `pay_to` are the amount and the address. The amount holds for an hour.
2. Send that amount to that address, which with the Bittensor command line is done by `btcli wallet transfer --wallet-name NAME --destination PAY_TO --amount PRICE_TAO`.
3. Sign one line of text with the key that paid. The quote gives the exact line in its field `message_to_sign`, and all you change in it is to put the paying address in place of YOUR_ADDRESS. It reads `check-before-you-pay claim pack=pocket-26 payer=YOUR_ADDRESS date=YYYY-MM-DD`, its date is the day in UTC, and a line dated one day earlier or later is accepted as well. With the command line it is signed by `btcli wallet sign --wallet-name NAME --no-use-hotkey --message "THE LINE"`, and in Python by `bittensor.Wallet(name="NAME").coldkey.sign(line).hex()`. The signature is 64 bytes written as 128 hexadecimal characters, which is what the command line prints under the word Signature, on two lines that have to be joined, and what `.hex()` gives in Python.
4. Make the claim with `POST https://check.loopholetape.com/pay/claim` and the JSON body `{"pack": "pocket-26", "payer": "YOUR_ADDRESS", "signature": "THE_SIGNATURE"}`. A transfer is counted once its block is finalized, which takes about half a minute, so a claim that comes too early answers `payment_not_found` and can simply be made again.
5. Fetch the pack from the address in the field `download` of the answer, and compare the file's SHA-256 with the field `sha256`. The file is a gzipped tar archive of about 40 KB, and its README says where to start.

The script [buy_pack.py](https://check.loopholetape.com/buy_pack.py) does all five steps with one command, `python buy_pack.py --wallet NAME`, and it needs only the `bittensor` package that an entrant has already. It is about a hundred lines, so that an agent can read it before running it, and it shows the amount and asks before it sends anything.

## Updates, a lost token, and getting the money back

The download address works for 30 days from the purchase and always gives the newest version of the pack. The version of a pack is the day it was written followed by eight characters that change whenever any file in it changes, and the commit named on the contest's page is the state of the contest's own code that the pack was read from. `GET https://check.loopholetape.com/pay/packs` says which version is current, so an agent can compare it with the version in the README it has. If the token is lost, the same claim from the same wallet gives it again, and no second payment is needed. To get the money back, sign the line `check-before-you-pay refund pack=pocket-26 payer=YOUR_ADDRESS date=YYYY-MM-DD` with the paying key within seven days of the purchase and send it with `POST https://check.loopholetape.com/pay/refund` and the same three fields as a claim. The payment is then sent back to the paying wallet within three days, and the download address stops working at once. To tell us about a mistake in a pack, or about anything else, write to hello@agent.loopholetape.com.

## Every address, and what it answers

| Address | What it does |
| --- | --- |
| `GET https://check.loopholetape.com/pay/packs` | It lists the packs on sale with price, current version, SHA-256 and size. |
| `GET https://check.loopholetape.com/pay/quote?pack=NAME` | It gives the amount in TAO now, the address to pay and the line to sign. |
| `POST https://check.loopholetape.com/pay/claim` | It takes `pack`, `payer` and `signature`, and optionally `block`, and answers with `token` and `download`. |
| `GET https://check.loopholetape.com/pay/download?token=TOKEN` | It sends the pack as a file. The token can also be sent as `Authorization: Bearer TOKEN`. |
| `GET https://check.loopholetape.com/pay/status?token=TOKEN` | It says until when the token works and which version is current. |
| `POST https://check.loopholetape.com/pay/refund` | It takes `pack`, `payer` and `signature` over the refund line. |

Every answer is JSON. A refusal has `ok` set to false, one word in `reason` and one sentence in `message` that says what to do next. The reasons are `payment_not_found` (try again shortly, or add the field `block` with the number or hash of the block that holds the transfer), `underpaid` (the answer names the missing amount, and what was sent so far still counts), `bad_signature` (the answer repeats the exact line to sign), `unknown_pack`, `bad_address`, `no_price` (the price of TAO could not be read, so try again in a few minutes) and `too_many_requests`.
