> For the complete documentation index, see [llms.txt](https://mogami.gitbook.io/mogami/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mogami.gitbook.io/mogami/learning/x402-hands-on.md).

# X402 hands-on

## How it works ?

<figure><img src="/files/LmgRwq2ia8QyVOzficnv" alt=""><figcaption></figcaption></figure>

## Manage wallet & funds

You can generate a key pair with the command:

```bash
cast wallet new
```

For the sake of this document, we will use the following key pairs:

**Client (buyer)**\
Address: `0x2980bc24bBFB34DE1BBC91479Cb712ffbCE02F73`\
Private key: `0x9d2675820d55300a05c8991df217a619bcfdc86e2fd91e56443dbbcf159337fd`

**Server (seller)**\
Address: `0x7553F6FA4Fb62986b64f79aEFa1fB93ea64A22b1`\
Private key: `0xf4f7e165433421377856179c698aa387bd8f872657977bd8fa6d62604f41773c`

You can add funds to your wallet using the [CDP faucet](https://portal.cdp.coinbase.com/products/faucet).

## Getting ready

You need to install Foundry (explained in the README) and those tools:

```bash
npm install -g pnpm
```

Then, you can download the sources:

```bash
git clone git@github.com:coinbase/x402.git
```

## Make it work

Coinbase provides an example server [here](https://github.com/coinbase/x402/tree/main/examples/typescript/servers/express).

```bash
cd x402/examples/typescript/servers/express/
cp .env-local .env
```

Edit .env and have those two lines to `ADDRESS=0x2980bc24bBFB34DE1BBC91479Cb712ffbCE02F73`.

Then you can run the server:

```bash
cd ../../
pnpm install
pnpm build
```

Now, to run the server:

```bash
cd servers/express
pnpm install
pnpm dev
```

Now, we will run a client.

```bash
cd ../../clients/fetch
cp .env-local .env
```

Edit .env and have those two lines to

```
ADDRESS=0x2980bc24bBFB34DE1BBC91479Cb712ffbCE02F73
PRIVATE_KEY=0x9d2675820d55300a05c8991df217a619bcfdc86e2fd91e56443dbbcf159337fd
```

```bash
pnpm install
pnpm dev
```

You will get a message like this:

```
{ report: { weather: 'sunny', temperature: 70 } }
{
  success: true,
  transaction: '0x83645ca1dd0a5a59653748c8a63dd65126a8dd6097ca3f98fe4b27325f2fa92f',
  network: 'base-sepolia',
  payer: '0x2980bc24bBFB34DE1BBC91479Cb712ffbCE02F73'
}
```

The transaction can be seen [here](https://base-sepolia.blockscout.com/tx/0x83645ca1dd0a5a59653748c8a63dd65126a8dd6097ca3f98fe4b27325f2fa92f).
