随笔分类 -  Solidity基础

摘要:父合约 contract fruit{ string public name = 'eat'; } 继承 import "/4_.sol"; contract Apple is fruit { function getType() external view returns(string memor 阅读全文
posted @ 2022-06-09 23:43 apeNote 阅读(22) 评论(0) 推荐(0) 编辑
摘要:A合约调用B合约 合约B contract B { uint public x; uint public value; function setX(uint _x) public returns (uint){ x = _x; return x; } function setXandSendEthe 阅读全文
posted @ 2022-06-08 23:29 apeNote 阅读(391) 评论(0) 推荐(0) 编辑
摘要:delegateCall 用于重定向父合约; A 合约越来调用B1, 将地址改为 B2 就可以调用 B2 合约B1 contract B { uint public num; uint public value; function setVars(uint _num) public payable{ 阅读全文
posted @ 2022-06-08 22:10 apeNote 阅读(138) 评论(0) 推荐(0) 编辑
摘要:例子 receive contract ReceiveTest { event Received(address caller, uint256 amount, string msg); function getBalance() public view returns(uint256){ retu 阅读全文
posted @ 2022-06-08 11:52 apeNote 阅读(90) 评论(0) 推荐(0) 编辑
摘要:test pragma solidity >=0.7.0 <0.9.0; contract ReceiveTest { string public data; receive() external payable{ data = "receive call"; } fallback() extern 阅读全文
posted @ 2022-06-08 09:55 apeNote 阅读(32) 评论(0) 推荐(0) 编辑
摘要:recieve 接收token函数 pragma solidity >=0.7.0 <0.9.0; contract ReceiveTest { receive() external payable{ } fallback() external payable{ } function getBala 阅读全文
posted @ 2022-06-06 15:21 apeNote 阅读(306) 评论(0) 推荐(0) 编辑
摘要:payable 的使用 合约可以接受 token, 也可以发送 token 通过使用 payable 关键字。 1、通过修饰方法, 例子1 一个充值函数,一个体现函数 pragma solidity >=0.7.0 <0.9.0; contract Payable { mapping(address 阅读全文
posted @ 2022-06-06 09:59 apeNote 阅读(451) 评论(2) 推荐(0) 编辑
摘要:Solidity 语法里面用到的两种变量类型 Memory 和 Storage 的关系就像电脑的内存和硬盘的,memory 是和内存一样是暂时存储,storage 像硬盘一样是永久存储。 memory 是值传递,storage 是引用类型 在合约里面,函数外的变量默认通过 storage 存储,函数 阅读全文
posted @ 2022-05-13 21:57 apeNote 阅读(524) 评论(0) 推荐(0) 编辑
摘要:Map 例子 contract MapTest { mapping(address => uint256) public account; function getAccount(address _addr) public view returns (uint256){ return account 阅读全文
posted @ 2022-05-09 22:31 apeNote 阅读(285) 评论(0) 推荐(0) 编辑
摘要:数组 例子 contract ArrayTest { uint256[] public array01; uint256[] public array02=[1,2,3]; function push(uint256 i) public{ array01.push(i); } function po 阅读全文
posted @ 2022-05-09 22:18 apeNote 阅读(118) 评论(0) 推荐(0) 编辑
摘要:循环代码 contract LoopTest { uint256 public counter; function loopTest(uint n) public { for(uint i=0; i<n; i++){ counter += 1; } } } 输出 阅读全文
posted @ 2022-05-05 08:59 apeNote 阅读(64) 评论(0) 推荐(0) 编辑
摘要:assert contract ErrorTest { uint256 public balance; function deposit(uint256 _amount) public{ balance = balance + _amount; } function withdraw(uint256 阅读全文
posted @ 2022-05-05 08:54 apeNote 阅读(10) 评论(0) 推荐(0) 编辑
摘要:test contract EventTest { event Log1(address sender, uint256 val); string log; function test() external{ emit Log1(msg.sender, 100); log = 'logTest'; 阅读全文
posted @ 2022-05-05 00:41 apeNote 阅读(26) 评论(0) 推荐(0) 编辑
摘要:继承 一、 这个food合约部署后,可以获取到返回字段 contract Food { function getFood() public pure virtual returns(string memory){ return "food"; } } 1.1、继承 创建一个 Meat 合约使用继承属 阅读全文
posted @ 2022-04-28 22:12 apeNote 阅读(69) 评论(0) 推荐(0) 编辑
摘要:solidity 的 构造函数和 java 也是一样的,初始化执行。 contract ConstructorTest { uint256 public price; constructor(uint256 _input){ price = _input; } } 在部署的时候,需要设置值, 不然会 阅读全文
posted @ 2022-04-18 20:13 apeNote 阅读(162) 评论(0) 推荐(0) 编辑
摘要:修饰器,通过定义一个方法,使用该方法去修饰其他方法。 用个没有用修饰器的例子说明,onlyOwner 是一个校验地址是不是原来账号的地址的方法。 将该合约部署 contract Test { address public owner; uint256 public price; constructo 阅读全文
posted @ 2022-04-18 20:03 apeNote 阅读(88) 评论(0) 推荐(0) 编辑
摘要:一、常量 solidity 常量支持 值类型 和 字符串类型 contract ConstantTest { uint constant x = 11 ** 11; string constant text = "abcdefg"; } 二、变量 solidity 的变量和 其他语言一样,分为局部变 阅读全文
posted @ 2022-04-13 13:16 apeNote 阅读(280) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示