# ecash-agora: Non-interactive XEC -> token swaps using Script
## What's an "Agora"?
The agora (ἀγορά) was a central public space in ancient Greek city-states, and means "market" in modern Greek. The eCash Agora is similar in that sense, it's a protocol on eCash that allows anyone to offer their tokens in exchange for XEC.
## Is Agora a DEX?
Agora is a NEX, a "non-custodial exchange"; in contrast to e.g. Uniswap or other DEXes that are common on ETH, Agora doesn't pool any funds, but everyone offering tokens has them in their own independently controlled UTXOs.
You don't send your tokens to a central smart contract, you keep them in your wallet but expose them for others to take if they meet certain criteria.
In that sense, "exchange" might even be a misnomer, as there's no special server or platform required, it's using the P2P network directly, and trades are accepted on and broadcast from the user's own wallets.
## How can it be used?
eCash Agora allows users to lock their SLP/ALP tokens in a special UTXO, which behaves similar to to a "virtual vending machine", where other's can "insert" XEC and get tokens out.
For example, Alice can lock 1000 GRUMPY into an output with a Agora P2SH Script, and in the rules of the Script it requires others to send 20000 XEC to an output with an address controlled by Alice.
So, if Bob has 20000 XEC, he can send the 1000 GRUMPY to his own address by spending Alice's output with a transaction that sends the 20000 XEC to Alice. And the Agora Script enforces that this is handled correctly.
## Why does it work?
We can use Bitcoin's Script language to put spending conditions on a UTXO, for example a normal P2PKH requires us to provide a matching public key + signature, like this:
These Scripts are little programs that a spender has to make happy (i.e. make them result in producing a "true" result) in order to spend them.
eCash has the ability to put conditions on a transaction spending a UTXO for a while already, you can read about them [here](https://read.cash/@pein/bch-covenants-with-spedn-4a980ed3).
**We can use this to constrain that an output can only be spent if it sends some XEC to a specific address, which is essentially all that Agora does**
At the end, it's an `OP_EQUALVERIFY` operation that will fail if someone tries to get the tokens without sending the required tokens to the required address.
## How does it work?
### Transaction
A transaction will look roughly like this, if Bob accepts all available tokens:
2. You may need to [adjust](https://stackoverflow.com/questions/72409563/unsupported-hash-type-ripemd160-with-hashlib-in-python/72508879#72508879) your `openssl` settings
3. Specify the location of your built chronik-with-plugins node with the `BUILD_DIR` env variable, e.g.
Running from `bitcoin-abc/modules/ecash-agora` if your build dir is `bitcoin-abc/build/`:
`BUILD_DIR="${PWD}/../../build" npm run integration-tests`
- Plugin support [D16745](https://reviews.bitcoinabc.org/D16745)|[D16753](https://reviews.bitcoinabc.org/D16753)|[D16754](https://reviews.bitcoinabc.org/D16754)|[D16755](https://reviews.bitcoinabc.org/D16755)
- Improve test framework [D16741](https://reviews.bitcoinabc.org/D16741)