Ethereum-based smart contract solidity learning diary

The realization of the first lesson helloworld in remix

pragma solidity ^0.4.16;//版本号最好设置成0.4.16之后的版本,之前的版本在一些问题上面会报错

contract HelloWorld{
    string Myname = "chelsea";
    
    function getName() public returns(string)
    {
        return Myname;
    }
    
    function changeName(string _newName)public
    {
        Myname =  _newName;
    }
    
    function  pureTest(string _name) pure public returns(string){
        return  _name;
    }
}

Specific interface presentation

Lesson 2 is mainly some Boolean statements.

pragma solidity ^0.4.16;

contract booleanTest{
    
    bool _a;
    int num1=100;
    int num2=100;
    function getBool() returns(bool)
    {
        return _a;
    }
    
    function getBool1() returns(bool)
    {
        return !_a;
    }
    
    function panduan() returns(bool)
    {
        return num1==num2;
    }
    
    function panduan2() returns(bool)
    {
        return num1!=num2;
    }
    function yu() returns(bool){
        return (num1==num2)&&true;
    }

}

Lesson 24 - Lesson 31 Addresses and Transactions

1. The essence of Ethereum address (p24)

pragma solidity ^0.4.16;

contract addresstest{
    address public account;//初始时默认地址为0,外部地址为0xca35b7d915458ef540ade6068dfe2f44e8fa733c(40个字节160位)等价于 unit160,账户地址代表拥有账户
    
}

page after running

Click Deploy. After the deployment is complete, the contract will also have an address. This address 0xe90f4f8aeba3ade774cac94245792085a451bc8e is deployed on the blockchain network
![](https://img-blog.csdnimg.cn/df8e7800174d4b24a851684b00cee2d7.png
and then a verification is performed on whether it is 160 bits. This part reported an error and has not been adjusted specifically (the function is unit160 and address for coercion)

pragma solidity ^0.4.16;

contract addresstest{
    address public account;//0xca35b7d915458ef540ade6068dfe2f44e8fa733c
    
    function changeIt() returns(unit160){//报的错误是6:33.declarationError
        return unit160(account);
    }
}

Then explain how to judge the address, judge the size, and judge based on the numerical size of the address

pragma solidity ^0.4.16;

contract addresstest{
    address public account=0xca35b7d915458ef540ade6068dfe2f44e8fa733c;
    
    address account1=0xca35b7d915458ef540ade6068dfe2f44e8fa733c;
    address account2=0x0de37dce8154ce54d895bd16942c86d568ddb5fc;
    
    function changeIt() view returns(address){
        return address(0xe90f4f8aeba3ade774cac94245792085a451bc8e);
    }
    
    function check1() view returns(bool){//加上view之后能够更加直观的在右方看到结果
        return account1>account2;
    }
    
    function check2() view returns(bool){
        return account1>=account2;
    }
    
    function check3() view returns(bool){
        return account1<account2;
    }
    
    function check4() view returns(bool){
        return account1<=account2;
    }
}

Result presentation

2. Transfer funds using a wallet (p25)

The contract has an address, so Ether can still be stored on this address. How to send Ether to the contract user when calling the address. When calling the function, send the value, which is the transaction amount, to the address of the contract. When calling the function, send the
insert image description here
value Information, send ether to the address of the account, after clicking the pay button, it will send 10ether shown in the picture to the address of the smart contract

Guess you like

Origin blog.csdn.net/chelseaz/article/details/121268758