Skip to content

Commit 13d2ff7

Browse files
committed
docs: correct run instructions and sell amount log in the swap example
The header said the API key could go in a .env file, but nothing in the repo loads one — no dotenv dependency, and the script reads process.env directly. Running it as documented failed with "ZERO_EX_API_KEY is not set" despite a populated .env. Document --env-file instead. Also print the decimal-adjusted sell amount rather than raw base units, so the opening line matches the "Sell: 100 USDC" line below it, and scope the funded-wallet prerequisite to execution — the script as written is quote-only.
1 parent 79a0489 commit 13d2ff7

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

‎examples/swap-usdc-to-weth.js‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
// Example: Swap 100 USDC for WETH on Ethereum mainnet using the 0x Swap API v2.
22
//
33
// Prerequisites:
4-
// 1. Set ZERO_EX_API_KEY in your environment (or in a .env file).
4+
// 1. Set ZERO_EX_API_KEY in your environment, or put it in a .env file and
5+
// pass --env-file (nothing here loads .env automatically).
56
// 2. Install dependencies: npm install
6-
// 3. Provide a funded EVM wallet account (see note below).
7+
// 3. Provide a funded EVM wallet account (only to execute; see note below).
78
//
8-
// Run: node examples/swap-usdc-to-weth.js
9+
// Run: node --env-file=.env examples/swap-usdc-to-weth.js
10+
// or: ZERO_EX_API_KEY=... node examples/swap-usdc-to-weth.js
911

1012
import ZeroExProtocol from '../index.js'
1113

@@ -46,7 +48,7 @@ const protocol = new ZeroExProtocol(undefined, {
4648

4749
// ─── Step 2: Get an indicative quote ─────────────────────────────────────────
4850

49-
console.log(`\nFetching indicative price for ${SELL_AMOUNT} USDC → WETH on chain ${CHAIN_ID}…`)
51+
console.log(`\nFetching indicative price for ${Number(SELL_AMOUNT) / 1e6} USDC → WETH on chain ${CHAIN_ID}…`)
5052

5153
const quote = await protocol.quoteSwidge({
5254
fromToken: USDC,

0 commit comments

Comments
 (0)