Helper Calls
Part of the Fundamentals section of Coddy's Solidity journey. Lesson 24 of 53.
One helper can call another helper to break a calculation into meaningful steps. The outer helper uses the returned value, then returns its own result. An internal function can be called directly by name from another function in the contract.
Define this helper inside the contract:
function twice(uint256 n) internal pure returns (uint256) {
return n * 2;
}
function adjusted(uint256 n) internal pure returns (uint256) {
return twice(n) + 4;
}Use it inside the provided main function:
console.log(adjusted(6));adjusted calls twice, which returns twelve, then adds four. main sees only the final sixteen. This division keeps the repeated doubling rule in one place while another helper describes the extra adjustment.
An internal helper can call another internal helper directly by name.
Challenge
EasyWrite pure internal helpers doubleValue, returning n times two, and withBonus, returning doubleValue(n) plus five. Print withBonus(points).
The tests pass arguments to main in this order: uint256 points. 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 points) external view {
// Write your solution here.
}
}This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
Practice on your own: Solidity playground