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则表现为字节数组
  • 相关阅读:
    酒里放茶,醉,未遂。
    利用自定义事件实现不同窗体间的通讯 Delphi篇
    主题:CS0016: 未能写入输出文件“c:\WINDOWS\Microsoft.NET\***.dll”错误处理
    delphi點擊窗體最小化,關閉按鈕時的托盤圖標設置
    delphi制作程序啟動歡迎窗體
    那年 那雪
    DOL魔盘解决方案
    专家解密“艳照门”背后三大安全陷阱
    jQuery获取Select选择的Text和 Value(转)
    技术列传 guava cache
  • 原文地址:https://www.cnblogs.com/eilinge/p/9950580.html
Copyright © 2011-2022 走看看