Solidity-003 BoolContract.sol

2024-01-07 21:24:34

// SPDX-License-Identifier: DataSummer

pragma solidity ^0.8.9;?

?
// This is a Solidity contract named BoolContract
contract BoolContract {?

? ? // This boolean variable is used to store the payment status
? ? bool isPaid = true;?

? ? // This function is used to manage the 'isPaid' boolean variable
? ? // It sets 'isPaid' to false and returns the updated value, which will be false
? ? function manageBool() public returns (bool) {?
? ? ? ? isPaid = false;?
? ? ? ? return isPaid; //returns false?
? ? }?

? ? // This function is used to demonstrate converting 'isPaid' (boolean) to 'uint8' (unsigned integer)
? ? // It sets 'isPaid' to false and returns the constant value 10 as a 'uint8' type
? ? // The commented line below would cause an error because 'isPaid' cannot be directly converted to 'uint8'
? ? function convertToUint() public returns (uint8) {?
? ? ? ? isPaid = false; ? ? ??
? ? ? ? return 10;
? ? ? ? // return uint8(isPaid); //error?
? ? }?
} ??
?

//Deploy screenshot show:

文章来源:https://blog.csdn.net/m0_61408373/article/details/135423233
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。