dyce
v1.0.1
Published
The official JavaScript library for the Dyce API
Readme
DyceAPI JavaScript API Library
This library provides convenient access to the Dyce API from JavaScript.
Overview
This project aims to revolutionize the way users pay for online services by introducing a cryptocurrency pay-as-you-go pricing model. Many existing subscription models, including tiered subscriptions, can be costly for users who don't fully utilize the service. Our API addresses this issue by leveraging stablecoin technology to enable direct, flexible payments based on actual usage.
Installation
npm install dyceDashboard API Documentation
Requests will be sent to AWS API Gateway where they will be handled by serverless lambda functions. This gateway will require the use of an API key which can be acquired by registering for one in the Dyce Dashboard. All requests require an x-api-key header:
{ "x-api-key": string }Payments Endpoints
get-wallet-address
- Description: Retrieves the address for a specified wallet.
- Method:
GET - Response:
On success:
200 OK
{ "address": string }On failure:
404 Not Found
{ "message": "API key required/not found" }401 Unauthorized
{ "message": "No wallet set for API key" }approve-spending
- Description: Approves spending from a specified wallet. Used for pay-as-you-go transactions.
- Method:
POST - Request Body:
{ "userId": string, "wallet": string- wallet address, "amount": number } - Response:
On success:
200 OK
{ "message": "Spending approved" }On failure:
400 Bad Request
{ "message": "User ID, wallet address, and approve amount required" }401 Unauthorized
{ "message": "Invalid API key" }request-payment
- Description: Requests a payment to a specified address. Regular transaction endpoint.
- Method:
POST - Request Body:
{ "userId": string, "amount": number } - Response:
On success:
200 OK
{ "message": "Processed payment successfully" }On failure:
400 Bad Request
{ "message": "User ID and payment amount required/No spending approved/Insufficient spending limit" }401 Unauthorized
{ "message": "API key required/Invalid" }404 Not Found
{ "message": "No wallet set for API key" }/api/permit-spending
Description: Submits a signed EIP-2612 permit for a user, allowing spending without requiring a MetaMask popup. Useful for enabling pay-as-you-go transactions programmatically.
Method:
POSTRequest Body:
{
"userId": "string",
"permit": {
// EIP-2612 typed data
},
"contractAddress": "string"
}- Response: On success:
200 OK
{
"message": "Permit submitted successfully"
}On failure:
400 Bad Request
{
"message": "User ID, permit, and contract address required"
}401 Unauthorized
{
"message": "API key required/Invalid"
}404 Not Found
{
"message": "No wallet set for API key"
}/api/receive-payment
Description: Submits a signed permit to collect payment from a user’s wallet. This completes a pay-as-you-go transaction on-chain using EIP-2612-compatible tokens.
Method:
POSTRequest Body:
{
"permit": {
// EIP-2612 typed data
},
"contractAddress": "string"
}- Response: On success:
200 OK
{
"message": "Payment received successfully"
}On failure:
400 Bad Request
{
"message": "Permit and contract address required"
}401 Unauthorized
{
"message": "API key required/Invalid"
}404 Not Found
{
"message": "No wallet set for API key"
}Usage Example
import Dyce from "dyce"
const dyce = new Dyce(process.env['DYCE_API_KEY']);
const userId = "user_123"
const amount = 10
// Get payment from user wallet (with approval)
const success = dyce.transferTokens(amount);
if (success) console.log("Executed payment!");
else console.error("Failed to execute payment!");
// Approve amount to be taken from user's wallet
const success = dyce.approveSpending(userId, amount);
if (success) console.log("Approved spending!");
else console.error("Failed to approve spending!");
// Get payment from user wallet (without approval)
const success = dyce.requestPayment(userId, amount);
if (success) console.log("Executed payment!");
else console.error("Failed to execute payment!");