Inventory Tracker
Part of the Fundamentals section of Coddy's Solidity journey. Lesson 51 of 53.
Challenge
HardMaintain a mapping from item IDs to stock counts. Add firstQty at firstId and secondQty at secondId, then remove used from the stock at firstId. Print the final stock at firstId, then at secondId. IDs may be equal. used never exceeds the stock available at firstId after both additions.
The tests pass arguments to main in this order: uint256 firstId, uint256 firstQty, uint256 secondId, uint256 secondQty, uint256 used. Each test starts with fresh contract state.
Use console.log for the requested output. Print only the requested values, one per line, with no extra labels unless the task specifies them.
Try it yourself
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
import "forge-std/console.sol";
contract Main {
function main(uint256 firstId, uint256 firstQty, uint256 secondId, uint256 secondQty, uint256 used) external {
// Write your solution here.
}
}All lessons in Fundamentals
Practice on your own: Solidity playground