第51篇 笔记-如何将自定义数据写到区块链中(合约方式)

本文环境:

区块链版本:以太坊POA联盟链

节点版本: geth 1.9.19

nodejs版本:v10.14.0

操作系统:windows 64

本文提供另外一个方式,通过智能合约函数的方式把数据写到智能合约的变量区,其数据存储在storage区域,可通过函数查找出来。

1.智能合约

pragma solidity ^0.4.24;
 
contract LongRecord{

    mapping (uint => string) Record;
	
    uint private recordID=0;
    address private owner;
	
    constructor() public {
        owner = msg.sender;
    }
	
    function record(string s) public{
        require(msg.sender == owner);
        Record[recordID]=s;
        recordID++;
    }
	
    function getRecord(uint i) constant public returns (string){
        require(msg.sender == owner);
        return Record[i];
    }
}

在 remix 部署该合约:

猜你喜欢

转载自blog.csdn.net/wonderBlock/article/details/113527444