【solidity】helloWorld_boolean(01)

Page content

这篇文章简单的整理了solidity的HelloWorld和Boolean类型。

1.HelloWorld

先看solidity的一段代码

pragma solidity ^0.4.0;

contract HelloWorld {
    string MyName = "testName";
    
    function getName() public view returns(string){
        return MyName;
    }

    function changeName(string _newName) public {
        MyName = _newName;
    }

    function puerTest(string _name) pure public returns(string) {
        return _name;
    }
}

下一步编译
图片备用地址
solidity_01

下一步执行
图片备用地址
solidity_02

图片备用地址
solidity_03

图片备用地址
solidity_04

当每次执行changeName时以太币会减少
图片备用地址
solidity_05

2.Boolean

pragma solidity ^0.4.0;

contract BooleanTest{
    bool _a;
    int num1 = 100;
    int num2 = 200;

    function getBool() public view returns(bool) {
        return _a;//false
    }

    function getBool2() public view returns(bool){
        return !_a;//true
    }

    function panduan() public view returns(bool){
        return num1==num2;//false
    }

    function paduan2() public view returns(bool){
        return num1!=num2;//true
    }

    function yu() public view returns(bool) {
        return (num1==num2) && true;//false
    }

    function yu2() public view returns(bool) {
        return (num1!=num2) && true; //true
    }
}

欢迎大家的意见和交流

email: li_mingxie@163.com