Take out a loan

This guide explains how to take out a loan from an inventory pool

Prerequisites

  • An account that has been whitelisted as a borrower on the target inventory pool

  • A sufficient amount of collateral deposited

Process Overview

  1. Request a borrow digest from the API

  2. Sign the digest with your private key

  3. Submit the borrow request with your signature

  4. Execute the resulting transaction on-chain

Step 1: Request Borrow Digest

This step authenticates your request, preventing any other address from requesting a borrow on your behalf.

Make a GET request to https://api.nomial.io/borrow/digest with the following query parameters:

Name
Description

chain_id

The chain ID (e.g., 1 for Ethereum mainnet)

pool

The inventory pool address

borrower

Your borrower address

amount

The amount of ERC20 to borrow (in base units)

recipient

The address that will receive the borrowed funds (can be same as borrower)

expiry

Unix timestamp when the request expires (e.g., 1 hour in the future)

salt

Arbitrary 32-byte hex string to ensure request uniqueness

Example

The API will return a digest that needs to be signed by your borrower address

Step 2: Sign the Digest

Sign the provided hex digest directly with the private key of your borrower address. The resulting signature must use the standard 65-byte Ethereum format (r, s, v).

Be sure to sign the raw digest, without including an ERC-191 (“Ethereum Signed Message”) prefix.

Using Foundry cast to sign manually

You can use the cast CLI tool to sign the digest manually with the cast wallet sign command

Step 3: Submit Borrow Request

Make a POST request to https://api.nomial.io/borrow. This should include identical parameters and values to your digest request, with the addition of signature (your signature of the request digest).

If your borrow request is valid, the API will return a transaction with validator signatures that can be executed to the inventory pool's owner (access manager):

Step 4: Execute the Transaction

You can submit your signed transaction to the chain it was intended for. Here's an example using ethers.js:

Alternatively, you can construct the transaction yourself using the call object:

Note that you must execute your transaction on the access manager contract that is owner on the inventory pool, and not the inventory pool itself.

Last updated