Giter VIP home page Giter VIP logo

api-guide-example's Introduction

Smart Contract API Example

Example code for building your own Ethereum smart contract API in Node.js.

Setup

git clone [email protected]: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.

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.
const walletPrivateKey = process.env.walletPrivateKey;
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.

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

api-guide-example's People

Contributors

ajb413 avatar dependabot[bot] avatar hsien-hsiuliao avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.