手把手部署区块链智能合约及python的web3接口调用

手把手部署区块链智能合约及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。
至于各种命令要熟练使用,学习时可以参考这篇博文——命令行博文链接
本人在搭私链和部署智能合约的时候用到的命令如下,先列出来一下

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文件如下

[
	{
   
		"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": [
			{
   
				
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

权侑莉老婆

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值