Take out a loan
This guide explains how to take out a loan from an inventory pool
Last updated
curl "https://api.nomial.io/borrow/digest?\
chain_id=1&\
pool=0xabc123...&\
borrower=0xdef456...&\
amount=1000000&\
recipient=0xdef456...&\
expiry=1234567890&\
salt=0xabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdef"
{
"digest": "0x..." // The digest to sign
}cast wallet sign --private-key <BORROWER_PRIVATE_KEY> --no-hash <DIGEST>{
"chain_id": "1", // The chain ID
"pool": "0x...", // The inventory pool address
"borrower": "0x...", // Your borrower address
"amount": "1000000", // The amount to borrow in base units
"recipient": "0x...", // The address that will receive the borrowed funds
"expiry": "1234567890", // Unix timestamp when the request expires
"salt": "0x...", // The same salt used for the request digest
"signature": "0x..." // Your signature of the request digest
}{
"call": {
"chain": {
"id": "1",
"name": "ethereum"
},
"contract": {
"name": "InventoryPoolDefaultAccessManager01",
"address": "0x..."
},
"function": "borrow(address pool, uint256 amount, address recipient, uint256 expiry, bytes32 salt, bytes[] signatures)",
"selector": "0x...",
"calldata": "0x...",
"params": [
{
"name": "pool",
"value": "0x..."
},
{
"name": "amount",
"value": "1000000"
},
{
"name": "recipient",
"value": "0x..."
},
{
"name": "expiry",
"value": "1234567890"
},
{
"name": "salt",
"value": "0x..."
},
{
"name": "signatures",
"value": ["0x...", "0x..."]
}
]
},
"tx": {
"to": "0x...", // The access manager contract address
"data": "0x...", // The encoded function call data
"value": "0", // The amount of native token to send
"chain_id": "1" // The chain ID
},
"signed_digest": "0x...", // The digest that was signed
"validator_signatures": [ // Array of validator signatures
{
"validator": "validator1",
"signature": "0x..."
}
]
}const provider = new ethers.providers.JsonRpcProvider(rpcUrl);
const tx = {
to: response.tx.to,
data: response.tx.data,
value: response.tx.value
};
// Send the transaction
const result = await wallet.connect(provider).sendTransaction(tx);
await result.wait();// Import the contract ABI
const accessManagerABI = [
"function borrow(address pool, uint256 amount, address recipient, uint256 expiry, bytes32 salt, bytes[] signatures)"
];
// Create contract instance
const accessManager = new ethers.Contract(
response.call.contract.address,
accessManagerABI,
wallet
);
// Execute the borrow function
const result = await accessManager.borrow(
response.call.params[0].value, // pool
response.call.params[1].value, // amount
response.call.params[2].value, // recipient
response.call.params[3].value, // expiry
response.call.params[4].value, // salt
response.call.params[5].value // signatures
);
await result.wait();