当前位置:   article > 正文

手把手部署区块链智能合约及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"
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

安装好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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

如果要加进别的设备,那就要用其他命令来连接了,在部署智能合约时,你可以先部署在最先搭私链的这个节点上,部署成功后再想办法把别的设备连进来。搭私链步骤看这篇博客——搭私链
我的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": [
			{
   
				
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214
  • 215
  • 216
  • 217
  • 218
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/一键难忘520/article/detail/994268
推荐阅读
相关标签
  

闽ICP备14008679号