Prepare supply / borrow / withdraw / repay
prepare_actionBuild an unsigned transaction to supply, borrow, withdraw, or repay on Aave (v3 or v4). Returns an execution plan (a transaction to sign, or an approval step first). For a borrow or a withdraw, call preview_action first and read its warnings: the simulation is free, it commits nothing, and it is the cheapest way to learn the position cannot take the action - a withdraw of collateral pinned by an open borrow is the case that catches callers out. Non-custodial: the user's wallet signs and submits; nothing is sent here, so building one is free and commits the user to nothing. Choose sensible values, build it, and say what you chose - do not stop to ask the user first, because they see the transaction before they sign it. Send only the arguments that apply and leave every other one out: v4 takes 'reserveId'; v3 takes 'market' + 'token' + 'chainId'; 'max' is for withdraw and repay; 'enableCollateral' is for supply. Never send 'permitSignature' or 'permitDeadline' on a first call: they exist only to re-issue a call after an approval step handed you a permit to sign under 'bySignature', so if you have not been handed one, leave both out. Two things that catch callers out: a supply does NOT become collateral unless you pass enableCollateral:true, and without collateral the borrowing power is zero so any later borrow is refused; and collateral pinned by an open borrow cannot be withdrawn, so a withdraw has to repay first. After sending any transaction, poll get_transaction_processed before building the dependent next one.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| max | No | Withdraw/repay only: use the entire balance/debt. | |
| token | No | v3 only: underlying token address. | |
| action | Yes | Which action to build. | |
| amount | No | Amount in MAIN units (e.g. '10.5'), never base units: 100000 base units of a 6-decimal token is '0.1', not '100'. Convert before sending if the user stated base units. Omit only if max=true. | |
| market | No | v3 only: market pool address, from a get_markets row in this session. It cannot be recalled: an Aave pool address you already recognise belongs to another deployment (v2, or another chain) and is rejected. | |
| native | No | Use the chain's native gas token instead of an ERC-20. | |
| sender | Yes | Sender wallet address (0x, 40 hex): the wallet that will sign, as the user named it in this session. If no wallet has been named, ask for it; never substitute a placeholder, which is rejected. | |
| chainId | No | v3 only: chain id (positive integer). | |
| version | No | Optional: inferred from the reserve selector ('reserveId' is v4, 'market'+'token'+'chainId' is v3). Send it to be explicit, or if you somehow set both. | |
| reserveId | No | v4 only: the opaque reserveId, copied verbatim from a get_markets row or a get_position_items item in this session (e.g. 'MTo6MHg5NGU3...Ojo1') - it cannot be constructed or recalled, so fetch one before the first call rather than after a refusal. For a withdraw or a repay take it from get_position_items for the position being acted on, not from get_markets: the same asset exists on several spokes, and the one this wallet supplied is the only one it can exit. The 'spokeId' from get_user_positions is NOT this: it is the same encoding one segment short, names the spoke rather than a reserve inside it, and is rejected. A token symbol such as 'USDC' is rejected too. | |
| permitDeadline | No | Unix seconds, the 'deadline' from the permit message that was signed. Required with permitSignature. | |
| permitSignature | No | Send this only to replay a call after an approval handed you a permit to sign: the user's signature (0x...) over the PermitTypedData that approval carried under 'bySignature', on either version. It replaces the approval transaction, so the action comes back in one step. Requires permitDeadline. | |
| enableCollateral | No | supply only: also enable the asset as collateral (default false). Leave it off and the supply earns yield but backs no borrowing, so a following borrow fails for exceeding a borrowing power of zero. Pass true whenever the plan is to borrow against it. |