Mogami
  • Home
  • Roadmap & ideas
  • x402 in French
  • Java client SDK
    • Getting started
    • Example client
  • Java server SDK
    • Getting started
    • Example server
    • Configuration
  • Faciliator server
    • Getting started
    • Verifications
  • Learning X402
    • Protocol explanation
      • Get /weather without X-PAYMENT
      • Get /weather with X-PAYMENT
      • Payment verification on server
      • Payment settlement on server
    • X402 hands-on
    • Useful links
  • Contact
    • Email
    • Twitter
Powered by GitBook
On this page
  • How it works ?
  • Manage wallet & funds
  • Getting ready
  • Make it work
  1. Learning X402

X402 hands-on

PreviousPayment settlement on serverNextUseful links

Last updated 13 days ago

How it works ?

Manage wallet & funds

You can generate a key pair with the command:

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

Getting ready

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

npm install -g pnpm

Then, you can download the sources:

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

Make it work

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:

cd ../../
pnpm install
pnpm build

Now, to run the server:

cd servers/express
pnpm install
pnpm dev

Now, we will run a client.

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

Edit .env and have those two lines to

ADDRESS=0x2980bc24bBFB34DE1BBC91479Cb712ffbCE02F73
PRIVATE_KEY=0x9d2675820d55300a05c8991df217a619bcfdc86e2fd91e56443dbbcf159337fd
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'
}

You can add funds to your wallet using the .

Coinbase provides an example server .

The transaction can be seen .

CDP faucet
here
here