Micropay is a platform to consume and pay for API's in a simple way.
Contributor submits their API and cost per call to the platform. Platform allows searching and instantiating API for consumer.
When an API is requested by a consumer. Platform creates an API (connected through a Oracle). A contract is created that binds contributor and consumer into a micropayment contract.
This micro payment is a pre payment. Consumers should maintain enough balance to cover cost of using API.
On every run of API, user sends a message {Payment Address and Amount Owed}
off chain to the API contributor. In this application the messages is sent to google firebase (which acts as a broker for user and contributor).
Contributor sees the messages in realtime. They can verify the messages and submit the payment address, amount owed and signature of the user to close the payment channel and get the tokens owed to them.
Contracts enabling API distribution. During registration API Information contract is created. And when the API is requested by the user then a User specific contract and a Payment contract is created for the request.
Contributor is subscribed to Off chain storage. To close the withdraw channel and get payed, Contributor of the API can send signature for the message and message content (Payment contract address and Payment value) to the Payment contract. If the information provided is correct Tokens owed is sent to the Contributor and rest is sent back to the user.
Steps to setup and run project on your machine. Ensure that truffle is installed.
-
Clone the project
git clone https://github.com/anuragjha/Micropay-Web.git
-
Run the development console.
truffle develop
-
Compile and migrate the smart contracts. Note inside the development console we don't preface commands with
truffle
.compile migrate --reset
-
In the
app
directory, we run the React app.// in another terminal (i.e. not in the truffle develop prompt) cd app npm run start
-
Truffle can run tests written in Solidity or JavaScript against your smart contracts. Note the command varies slightly if you're in or outside of the development console.
// inside the development console test
-
Jest is included for testing React components. Compile your contracts before running Jest, or you may receive some file not found errors.
// ensure you are inside the app directory when running this npm run test
-
To build the application for production, use the build script. A production build will be in the
app/build
folder.// ensure you are inside the app directory when running this npm run build