單雙幣/字母幣流動性質押挖礦分紅系統開發詳細及方案

xiaofufu發表於2023-03-05

  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連線到區塊鏈的方式


  from web3 import Web3,HTTPProvider,IPCProvider,WebsocketProvider


  """


  HTTPProvider:用於連線基於http和https的JSON-RPC伺服器:透過完整的URI找到伺服器


  w3=Web3(HTTPProvider


  Web3.IPCProvider用於連線到基於ipc套接字的JSON-RPC伺服器:透過檔案系統路徑找到IPC套接字


  w3=Web3(IPCProvider(引數))


  Web3.WebsocketProvider用於連線到基於ws和wss websocket的JSON-RPC伺服器:透過完整的URI找到伺服器


  w3=Web3(WebsocketProvider


  """ 詳細方案及原始碼:MrsFu123


  w3=Web3(HTTPProvider


  print(w3)#<web3.main.Web3 object at 0x105d42510


  from web3 import Web3


  import web3


  CONTRACT='0x22C1f6050E56d2876009903609a2cC3fEf83B415'#合約地址


  HTTPProvider="主網HttpProvider


  #---開啟abi json檔案


  with open('contracts/contract_abi.json','r')as contract_abi:


  abi=json.load(contract_abi)


  #---提供HTTPProvider,鏈上互動的介面


  w3=Web3(Web3.HTTPProvider(HTTPProvider))


  #---檢查HTTPProvider


  print(w3.isConnected())


  #Web3.toHex(primary=None,hexstr=None,text=None)


  #接受各種輸入並以其十六進位製表示形式返回。它遵循JSON-RPC規範


  #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)


  #接受各種輸入並返回等效的位元組數。文字被編碼為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)


  #接受各種輸入並返回其等效的整數


  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"}


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69956839/viewspace-2938206/,如需轉載,請註明出處,否則將追究法律責任。

相關文章