手把手部署区块链智能合约及python的web3接口调用
说句实话,在做区块链、智能合约、搭私链、pythonWeb3接口调用这些东西的时候,心里崩溃了不止四五十回,如果可以选别的方向,博主劝你赶紧换,人生已经很不容易了,别给自己找罪受。。。。。
创世块是什么请自行搜索,网络上很多示例的创世块博主都试过,在实际使用时会有各种各样的问题,如挖矿难度过大,格式不标准等等,博主贴上自己用的创世块代码,可以避免不必要的问题。
{
"config": {
"chainId": 3838438,
"homesteadBlock": 0,
"eip150Block": 0,
"eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"eip155Block": 0,
"eip158Block": 0,
"byzantiumBlock": 0,
"constantinopleBlock": 0,
"petersburgBlock": 0,
"istanbulBlock": 0,
"ethash": {
}
},
"nonce": "0x0",
"timestamp": "0x5ddf8f3a",
"extraData": "0x0000000000000000000000000000000000000000000000000000000000000000",
"gasLimit": "0x47b888",
"difficulty": "0x2fffff",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000",
"alloc": {
},
"number": "0x0",
"gasUsed": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
}
安装好geth客户端,然后在geth.exe同级目录下按shift+鼠标右键出现如图所示菜单,选择在此处打开Powershell窗口
在控制台输入命令操控Geth。
至于各种命令要熟练使用,学习时可以参考这篇博文——命令行博文链接
本人在搭私链和部署智能合约的时候用到的命令如下,先列出来一下文章来源:https://www.toymoban.com/news/detail-764292.html
eth.sendTransaction({
from:eth.accounts[0],to:eth.accounts[1],value:web3.toWei(1, "ether")})
personal.unlockAccount(eth.accounts[0])
geth --datadir data0 init genesis.json
geth --datadir data0 --networkid 3838438999 --nodiscover --port 30306 console
eth.accounts
personal.newAccount()
personal.unlockAccount(eth.accounts[0])
admin.startRPC("127.0.0.1", 8585)
eth.blockNumber
admin.nodeInfo
如果要加进别的设备,那就要用其他命令来连接了,在部署智能合约时,你可以先部署在最先搭私链的这个节点上,部署成功后再想办法把别的设备连进来。搭私链步骤看这篇博客——搭私链
我的ABI文件如下文章来源地址https://www.toymoban.com/news/detail-764292.html
[
{
"inputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"name": "IPFSAddrMatch",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "string",
"name": "_IPFS",
"type": "string"
},
{
"internalType": "uint256",
"name": "_number",
"type": "uint256"
}
],
"name": "OverSubmit",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "_layer",
"type": "uint256"
},
{
"internalType": "bool",
"name": "_isVerifier",
"type": "bool"
},
{
"internalType": "uint256",
"name": "_number",
"type": "uint256"
}
],
"name": "Regist",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "_number",
"type": "uint256"
}
],
"name": "ViewFed",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "ViewLayerIPFS",
"outputs": [
{
"internalType": "string[]",
"name": "",
"type": "string[]"
},
{
"internalType": "string[]",
"name": "",
"type": "string[]"
},
{
"internalType": "string[]",
"name": "",
"type": "string[]"
},
{
"internalType": "string[3]",
"name": "",
"type": "string[3]"
},
{
"internalType": "uint256[3]",
"name": "",
"type": "uint256[3]"
},
{
"internalType": "uint256[3]",
"name": "",
"type": "uint256[3]"
},
{
"internalType": "uint256[3]",
"name": "",
"type": "uint256[3]"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "_number",
"type": "uint256"
}
],
"name": "ViewNode",
"outputs": [
{
"components": [
{
"internalType": "uint256",
"name": "BianHao",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "layer",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "lazy",
"type": "uint256"
},
{
"internalType": "bool",
"name": "valid",
"type": "bool"
},
{
"internalType": "bool",
"name": "isVerifier",
"type": "bool"
}
],
"internalType": "struct newBHZ.Node",
"name": "",
"type": "tuple"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "string",
"name": "_IPFS",
"type": "string"
}
],
"name": "addLazy",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"in
到了这里,关于手把手部署区块链智能合约及python的web3接口调用的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!