From e05a3f6d5785ce3bf817bc43c01064d46585a53b Mon Sep 17 00:00:00 2001 From: Pablo Gomes de Oliveira Date: Fri, 7 Nov 2025 01:21:18 +0300 Subject: [PATCH] Update README.md --- README.md | 81 +++++++++++++++++++++++++------------------------------ 1 file changed, 36 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index 7c6afa5..aa3e01d 100644 --- a/README.md +++ b/README.md @@ -1,79 +1,70 @@ # Smart Contract API Example -Example code for building your own Ethereum smart contract API in [Node.js](https://nodejs.org/en/download/). +Example code for building your own Ethereum smart contract API in Node.js (https://nodejs.org/en/download/). ## Setup -``` git clone git@github.com:compound-developers/api-guide-example.git cd api-guide-example npm install -``` **config.json** -The listed contract addresses and ABIs might be out of date. They can be confirmed here https://compound.finance/docs#networks. +The listed contract addresses and ABIs might be out of date. Confirm them here: https://compound.finance/docs#networks. **server.js** -1. Be sure to set an environment variable for the Ethereum wallet private -key. -2. Replace the HTTP Provider URL with your own. [Infura provides free API keys](https://infura.io/). +1. Set an environment variable for the Ethereum wallet private key. +2. Replace the HTTP Provider URL with your own (Infura provides free API keys: https://infura.io/). -```js -const walletPrivateKey = process.env.walletPrivateKey; -const web3 = new Web3('https://mainnet.infura.io/v3/_your_api_key_here_'); -``` +Example snippet: + + const Web3 = require('web3'); + const walletPrivateKey = process.env.WALLET_PRIVATE_KEY; + const web3 = new Web3('https://mainnet.infura.io/v3/_YOUR_API_KEY_HERE_'); ## Running -``` node server.js -``` ## API Endpoint Example Calls -These are the possible calls that can be made with [cURL](https://curl.haxx.se/download.html). - -```bash -curl localhost:3000/wallet-balance/eth/ -curl localhost:3000/wallet-balance/ceth/ -curl localhost:3000/supply/eth/9000 -curl localhost:3000/protocol-balance/eth/ -curl localhost:3000/redeem/eth/123 -``` +These are example calls you can make with cURL (https://curl.se/download.html). -Here is an example of outputs for a series of API calls. The wallet started out with 100 ETH. + curl localhost:3000/wallet-balance/eth/ + curl localhost:3000/wallet-balance/ceth/ + curl localhost:3000/supply/eth/9000 + curl localhost:3000/protocol-balance/eth/ + curl localhost:3000/redeem/eth/123 -```bash -curl localhost:3000/wallet-balance/eth/ -> 100 +Here is an example of outputs for a series of API calls. The wallet started with 100 ETH. -curl localhost:3000/wallet-balance/ceth/ -> 0 + curl localhost:3000/wallet-balance/eth/ + > 100 -curl localhost:3000/supply/eth/5 -> OK + curl localhost:3000/wallet-balance/ceth/ + > 0 -curl localhost:3000/protocol-balance/eth/ -> 4.999999999885010676 + curl localhost:3000/supply/eth/5 + > OK -curl localhost:3000/wallet-balance/eth/ -> 94.99788632 + curl localhost:3000/protocol-balance/eth/ + > 4.999999999885010676 -curl localhost:3000/wallet-balance/ceth/ -> 249.85542658 + curl localhost:3000/wallet-balance/eth/ + > 94.99788632 -curl localhost:3000/redeem/eth/249.85542658 -> OK + curl localhost:3000/wallet-balance/ceth/ + > 249.85542658 -curl localhost:3000/protocol-balance/eth/ -> 0 + curl localhost:3000/redeem/eth/249.85542658 + > OK -curl localhost:3000/wallet-balance/ceth/ -> 0 + curl localhost:3000/protocol-balance/eth/ + > 0 -curl localhost:3000/wallet-balance/eth/ -> 99.995909700269046879 + curl localhost:3000/wallet-balance/ceth/ + > 0 -``` + curl localhost:3000/wallet-balance/eth/ + > 99.995909700269046879