区块链web3的SimpleStorage.sol编写和实现

1.SimpleStorage.sol

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.7;

contract SimpleStorage{

uint256 favoriteNumber;

struct People{

uint256 favoriteNumber;

string name;

}

People\[\] public people;

mapping(string => uint256) public nameToFavoriteNumber;

function store(uint256 _favoriteNumber) public{

favoriteNumber = _favoriteNumber;

}

function retrieve() public view returns (uint256)

{

return favoriteNumber;

}

function addPerson(string memory _name, uint256 _favoriteNumber) public {

people.push(People(_favoriteNumber,_name));

nameToFavoriteNumber_name = _favoriteNumber;

}

}

相关推荐
木西1 天前
深度拆解 MyShell 底层:AI Agent 生态结算合约,如何实现安全防阻塞
web3·智能合约·solidity
笑容掩饰我的失落2 天前
区块链从小白到精通(十):合约安全与上线——重入攻击、Gas 优化与最佳实践
安全·区块链
Cooper252 天前
合约托管 + 验收释放:悬赏 DApp 的四态状态机与事件索引
web3·solidity
OxYGC3 天前
[Web3] 智能合约 04: 高级开发实战与 OpenZeppelin
web3·区块链·智能合约
笑容掩饰我的失落3 天前
区块链从小白到精通(七):Solidity 语法精讲——数据类型、函数、修饰器与事件
算法·区块链·php·智能合约·哈希算法
OxYGC3 天前
[Web3] 智能合约 03: 函数/事件/继承/接口/异常处理
web3·区块链·智能合约
笑容掩饰我的失落4 天前
区块链从小白到精通(八):从零实现一个标准 ERC-20 代币(完整可运行代码)
算法·区块链·php·智能合约·哈希算法
老谭说理财4 天前
股票市场全景评测与实战分析
区块链
OxYGC4 天前
[Web3] 智能合约 02: Solidity 基础语法
web3·区块链·智能合约
Bczheng15 天前
五十二.网络(2)--节点连接
区块链