区块链学习入门

网络为师,文章作伴。

在学习区块链的过程中遇到了不少问题,一一记录下来,方便日后总结回顾。

 

入门的文章

完全是看的这篇的(十分感谢博主),其中踩了个大坑就是 ABI的导入出了点问题

https://blog.csdn.net/jevior/article/details/81229860?spm=1001.2101.3001.6650.4&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-4.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-4.no_search_link

 这里把这篇文章的重要代码摘要出来方便阅读,直接复制粘贴到运行的时候可能会出一些问题,因为web3一直再更新,编译器的版本也不同

Solidity部分

    pragma solidity ^0.4.17;
     

    contract Data{
     

    string public data;
     

    function Data()public{

    data = "init data";

    }

    function setData(string str) public payable{

    data = str;

    }
     

    function getData() public view returns (string) {

    return data;

    }

    }

 WEB部分

    var Web3 = require("web3");

    var web3 = new Web3();

    web3.setProvider(new Web3.providers.HttpProvider("http://localhost:7545"));

    var abi = [{"constant":true,"inputs":[],"name":"getData","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"str","type":"string"}],"name":"setData","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":true,"inputs":[],"name":"data","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"}];

    var address = '0x345ca3e014aaf5dca488057592ee47305d9b3e10';

    var data = new web3.eth.Contract(abi,address);


    data.methods.getData().call(null,function(error, result){

    console.log("the data:"+result);

    });
     

    data.methods.setData("hello blockchain").send({from: '0x627306090abaB3A6e1400e9345bC60c78a8BEf57'}).on('transactionHash', function(hash){

    console.log("hash:", hash);

    data.methods.getData().call(null,function(error, result){

    console.log("the data:"+result);

    });

    });

 

发币文章

发币我看的是这篇文章,比较详细,说是发币,其实是赋予(强加)代码一个属性

文章的链接:https://blog.csdn.net/a6taotao/article/details/112602580   (十分感谢博主的分享)

这里面的文章写的是非常非常的不错,很详细,比外面买的很多书好多了。

发币过程可以配合这个视频一起看

https://www.bilibili.com/video/BV1TK4y1E7gW 

 

上一篇:论文解读-ACL-2021-ConSERT: A Contrastive Framework for Self-Supervised Sentence Representation Transfer


下一篇:小样本学习综述 “Generalizing from a Few Examples: A survey on Few-shot Learning”