Note 51-How to write custom data to the blockchain (contract method)

This article environment:

Blockchain version: Ethereum POA alliance chain

Node version: geth 1.9.19

nodejs version: v10.14.0

Operating system: windows 64

 

This article provides another way to write data to the variable area of ​​the smart contract through the smart contract function. The data is stored in the storage area and can be found through the function.

 

1. Smart contract

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];
    }
}

Deploy the contract in remix:

Guess you like

Origin blog.csdn.net/wonderBlock/article/details/113527444