In this lesson, you will:
Solidity files, which typically have a .sol
extension, can contain multiple contracts. However, it's a best practice to define one contract per file and name the file after the contract.
Solidity files (.sol
) can include more than one contract, but for clarity and organization, it's recommended to stick to one contract per file. Here's what you need to know:
contract
keyword followed by the contract name. The contract's body is enclosed in curly braces { }
.contract A {
/// foo simply returns true
function foo() public returns (bool) {
return true;
}
}
contract B {
/// bar simply returns false
function bar() public returns (bool) {
return false;
}
}
MyContract
, the file should be named MyContract.sol
.By following these practices, your Solidity code for Solana programs becomes more readable and easier to manage, especially as your projects grow in size and complexity.