單雙幣流動(dòng)性質(zhì)押挖礦系統(tǒng)開(kāi)發(fā)(開(kāi)發(fā)案例)丨子母幣流動(dòng)性質(zhì)押挖礦系統(tǒng)開(kāi)發(fā)源碼版
Web 3.0:refers to the Internet ecology in the next stage after the mobile Internet,mainly through blockchain and other technical means,to realize the decentralized network form,and to realize the Internet that simulates the real world experience and breaks the virtual and real boundaries;
Blockchain:a decentralized data structure.Data is stored on distributed nodes,and nodes are computers that provide computing power.They can be personal computers or servers.Both have the nature of both server and client.To modify data,more than half of the nodes are required,which greatly increases the difficulty and security of data modification,thus solving the distrust relationship between people and platforms;
1.web3連接到區(qū)塊鏈的方式
from web3 import Web3,HTTPProvider,IPCProvider,WebsocketProvider
"""
HTTPProvider:用于連接基于http和https的JSON-RPC服務(wù)器:通過(guò)完整的URI找到服務(wù)器
w3=Web3(HTTPProvider
Web3.IPCProvider用于連接到基于ipc套接字的JSON-RPC服務(wù)器:通過(guò)文件系統(tǒng)路徑找到IPC套接字
w3=Web3(IPCProvider(參數(shù)))開(kāi)發(fā)詳細(xì)及流程I35案例7O98開(kāi)發(fā)O7I8
Web3.WebsocketProvider用于連接到基于ws和wss websocket的JSON-RPC服務(wù)器:通過(guò)完整的URI找到服務(wù)器
w3=Web3(WebsocketProvider
"""
w3=Web3(HTTPProvider
print(w3)#<web3.main.Web3 object at 0x105d42510
from web3 import Web3
import web3開(kāi)發(fā)設(shè)計(jì):MrsFu123
CONTRACT='0x22C1f6050E56d2876009903609a2cC3fEf83B415'#合約地址
HTTPProvider="https://dai.poa.network"#主網(wǎng)HttpProvider
#---打開(kāi)abi json文件
with open('contracts/contract_abi.json','r')as contract_abi:
abi=json.load(contract_abi)
#---提供HTTPProvider,鏈上互動(dòng)的接口
w3=Web3(Web3.HTTPProvider(HTTPProvider))
#---檢查HTTPProvider
print(w3.isConnected())
#Web3.toHex(primary=None,hexstr=None,text=None)
#接受各種輸入并以其十六進(jìn)制表示形式返回。它遵循JSON-RPC規(guī)范
#def to_hex(
#primitive:Primitives=None,hexstr:HexStr=None,text:str=None
#)->HexStr:
print(Web3.toHex(10))#0xa
print(Web3.toHex(hexstr='0x00'))#0x00
print(Web3.toHex(text='asimov'))#0x6173696d6f76
#Web3.toText(primary=None,hexstr=None,text=None)
#接受各種輸入并返回其等效字符串。文本被解碼為UTF-8。
print(Web3.toText('0x1254'))#T
print(Web3.toText('0x6173696d6f76'))#asimov
print(Web3.toText(b'asimx6fx76'))#asimov
print(Web3.toText('6173696d6f76'))#asimov
#Web3.toBytes(primary=None,hexstr=None,text=None)
#接受各種輸入并返回等效的字節(jié)數(shù)。文本被編碼為UTF-8。
print(Web3.toBytes(0))#b'x00'
print(Web3.toBytes(b'sasas'))#b'sasas'
print(Web3.toBytes(hexstr='000F'))#b'x00x0f'
print(Web3.toBytes(hexstr='0x000F'))#b'x00x0f'
print(Web3.toBytes(text='asimov'))#b'asimov'
#Web3.toInt(primary=None,hexstr=None,text=None)
#接受各種輸入并返回其等效的整數(shù)
print(Web3.toInt(0))#0
print(Web3.toInt(0x00f))#15
print(Web3.toInt(b'x00x0F'))#15
print(Web3.toInt(hexstr='0x00F'))#15
#ValueError:invalid literal for int()with base 10:'sa'
#text:interpret as string of digits,like'12'=>12
print(Web3.toInt(text='10'))#10
#Web3.toJSON(obj)obj:Dict[Any,Any]
#接受各種輸入并返回等效的JSON。
print(Web3.toJSON({'asimov':'da'}))#{"asimov":"da"}