zoukankan      html  css  js  c++  java
  • ethereum(以太坊)(一)

      从这周开始,开始学习以太坊开发--solidity,开始决定往区块链方向发展,毕竟区块链技术应用广泛。一开始接触solidity开发语言不太习惯,毕竟一直在学习python语法,有很多都不能接受。有难度,我喜欢!!

    成功者往往会选择走人少走的,更艰难的路,只有做别人都很难实现的事,再加上个人加倍付出的努力,成功才更有意义!!!
    pragma solidity ^0.4.0;
    
    contract Test{
        string str1;
        uint8 _age;
        uint8 _height;
        uint8 _sex;
        address _owner;
        
        //函数名与与合约名一样则表示构造函数,内部赋值变量需要先声明状态变量   
      //Variables inside the construct cannot be called directly outside
    function Test(){ //==constructor _age = 10; _height = 140; _sex = 1; _owner = msg.sender;
         //uint public _mouth;ParserError }
    function setvalue(uint8 age){ _age = age; } function getvalue() constant returns(uint8){ return _age; } function setStrvalue(string pam){ str1 = pam; } //向字符串内传参,使用双引号("");若使用单引号('),SyntaxError: Unexpected token ' in JSON at position 1 function getStrvalue() constant returns(string){ return str1; } //未执行kill(),返回当前合约地址;执行kill(),error: Failed to decode output: TypeError: Cannot read property 'length' of undefined function getOwner() constant returns(address){ return _owner; } // 析构函数:当msg.sender为owner,删除合约地址 function kill() public{ if (_owner == msg.sender){ selfdestruct(_owner); } } }
    强制的数据位置(Forced data location)
        状态变量(State variables)强制为: storage
    默认数据位置(Default data location)
        函数参数及返回参数:memory
        复杂类型的局部变量:storage
    
    深入分析
    storage 存储结构是在合约创建的时候就确定好了的,它取决于合约所声明状态变量。但是内容可以被(交易)调用改变。
        Solidity 称这个为状态改变,这也是合约级变量称为状态变量的原因。也可以更好的理解为什么状态变量都是storage存储。
    
    memory 只能用于函数内部,memory 声明用来告知EVM在运行时创建一块(固定大小)内存区域给变量使用。
        storage 在区块链中是用key/value的形式存储,而memory则表现为字节数组
  • 相关阅读:
    【PAT】1020. Tree Traversals (25)
    Pongo建立信号基站-实际上还是考中位数
    从此不再惧怕URI编码:JavaScript及C# URI编码详解
    WebBrowser与IE的关系,如何设置WebBrowser工作在IE9模式下?
    命令行下开启与关闭windows防火墙关端口(转)
    MySql数据库批量备份命令
    C#检查文件是否被占用
    C#使用Gzip解压缩完整读取网页内容
    [转]免费电话网专用免费平台
    libQt5Core.so: undefined reference to `dlclose@GLIBC_2.4'
  • 原文地址:https://www.cnblogs.com/eilinge/p/9950580.html
Copyright © 2011-2022 走看看