Getting Started
Simplify your work with decentralized assets with DeFi API from P2P.ORG.
This article describes how the DeFi API process works in general. To see detailed guides for a specific protocol, refer to the Protocols Supported section.
The DeFi API supports the complete transaction lifecycle, from creation through execution. When a user initiates a deposit action, the API constructs the necessary transaction, awaits user signing, and submits it to the blockchain network.
The API includes the major group of transaction endpoints, with the transactions/steps/craft method serving as the primary interface for transaction creation—handling approximately 95% of operations. The data part with endpoints for getting details on earnings, positions, and rewards is also provided.
Action types
Currently, each vault integration supports the following operations:
approvePermit2: Allow the P2P.ORG smart contract to manage tokens by obtaining approval.deposit: Initiate a deposit transaction to delegate the assets.withdraw: Withdraw the assets to the wallet.
To start using the DeFi API, get an authentication token.
General flow
-
Get a schema with the step list.
To retrieve a schema describing which transactions are required for a specified action, protocol, chain, and strategy, send a GET request to /api/defi/v1/transactions/schema.
-
Upon the schema retrieved, construct the required transactions. Depending on the action type and the request data, a schema may include up to 3 transactions.
To initiate the constructing process, send a POST request to /api/defi/v1/transactions/steps/craft. Upon each request, a raw unsigned transaction is generated.
-
Sign each transaction using the transaction-type-specific libraries.
-
Check the status of the constructed transaction by using the /api/defi/v1/transactions/steps/result endpoint.
If the schema contains several transactions, for intermediate transactions, you may use a /api/defi/v1/transactions/steps/status endpoint.
-
Broadcast the final transaction to the network by sending a POST request to /api/defi/v1/transactions/broadcast.