Solidity学习疑问总结

1字节(Byte)=8位(bit)

创建对象?

    struct People {
        string name;
        uint age;
    }
    People public person = People({name:'ljq',age:12});

创建数组?查询mapping映射?

复制代码
contract SimpleStorage {
    mapping (string => uint256) public nameToFavoriteNumber;
    struct People {
        string name;
        uint age;
    }
    People[] public PeopleList;
    function addPerson(string memory name, uint256 age ) public {
        PeopleList.push(People({name:'qq',age:13}));
        nameToFavoriteNumber[name] = age;
    }
}
复制代码

 calldata,memory,storage?  calldata:不可修改的临时变量 memory:可修改的临时变量 storage:可修改的永久变量

import合约?

import "./SimpleStorage.sol";

contract StorageFactory {
    SimpleStorage public simpleStorage;
    function createSimpleStorageContract() public {
        simpleStorage = new SimpleStorage();
    }
}

与其它合约交互?

继承和重写?

复制代码
import "./SimpleStorage.sol";

contract ExtraStorage is SimpleStorage{
    // is:给ExtraStorage合约加一些额外的函数,同时也包含了SimpleStorage合约的所有功能
    // virtual: 允许该函数被重写
    function store(uint256 _favNumber) public virtual {
        favNumber = _favNumber + 5;
    }
}
复制代码

 

posted @   木木的奇奇  阅读(3)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
点击右上角即可分享
微信分享提示