Skip to content

sirdavos47/api-guide-example

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Smart Contract API Example

A minimal example showing how to build an Ethereum smart contract HTTP API with Node.js, Express and Infura.

Relevant files

Prerequisites

  • Node.js (recommended LTS)
  • An Ethereum provider URL (e.g. Infura project endpoint)
  • A wallet private key set in the environment

Security notice

  • Do NOT commit or store private keys in the repo. The server reads the private key from the environment variable walletPrivateKey (see walletPrivateKey).
  • Use a dedicated wallet with limited funds for testing.
  • Ensure your provider URL and keys are stored securely.

Quick setup

git clone [email protected]:compound-developers/api-guide-example.git
cd api-guide-example
npm install

Running

node server.js

API Endpoint Example Calls

These are the possible calls that can be made with cURL.

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

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/
> 100

curl localhost:3000/wallet-balance/ceth/
> 0

curl localhost:3000/supply/eth/5
> OK

curl localhost:3000/protocol-balance/eth/
> 4.999999999885010676

curl localhost:3000/wallet-balance/eth/
> 94.99788632

curl localhost:3000/wallet-balance/ceth/
> 249.85542658

curl localhost:3000/redeem/eth/249.85542658
> OK

curl localhost:3000/protocol-balance/eth/
> 0

curl localhost:3000/wallet-balance/ceth/
> 0

curl localhost:3000/wallet-balance/eth/
> 99.995909700269046879

About

Example Ethereum smart contract API made with Express.js and Infura.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • JavaScript 100.0%