公排互助開發方案丨公排互助系統開發詳解及說明丨公排互助系統原始碼案例設計

xiaofufu發表於2023-02-26

智慧合約的全生命週期包括:合約生成、合約釋出和合約執行。

  合約生成:其中合約規範和合約驗證至關重要。

  合約釋出:需要多個節點進行共識和驗證。

  合約執行:基於“事件觸發”,智慧合約會定期遍歷每個合約的狀態機和觸發條件,將滿足觸發條件的合約推送到驗證佇列。

  合約實現:透過賦予物件數字特性,將物件程式化並部署在區塊鏈上,同時改變數字物件的狀態(如分配轉移)和數值。

Smart contract is a computer protocol designed to spread,verify or execute contracts in an information-based manner.

  Smart contract is a set of commitments defined in digital form,which control digital assets and contain rights and obligations agreed by contract participants,and is automatically executed by computer system.

  The smart contract program is not only a computer program that can be executed automatically,but also a system participant.It can respond to the received information,receive and store value,and send information and value to the outside

  

  從部署的智慧合約中讀取資料:

  import json

  from web3 importWeb3,HTTPProvider

  from web3.contract importConciseContract

  #compile your smart contract with truffle first

  truffleFile=json.load(open('./build/contracts/greeter.json'))

  abi=truffleFile['abi']
  bytecode=truffleFile['bytecode']

  #web3.py instance

  w3=Web3(HTTPProvider(" Key here>"))

  print(w3.isConnected())

  contract_address=Web3.toChecksumAddress("<Deployed Contract Address here>")

  #Instantiate and deploy contract

  contract=w3.eth.contract(abi=abi,bytecode=bytecode)

  #Contract instance

  contract_instance=w3.eth.contract(abi=abi,address=contract_address)

  #Contract instance in concise mode

  #contract_instance=w3.eth.contract(abi=abi,address=contract_address,ContractFactoryClass=ConciseContract)

  #Getters+Setters for web3.eth.contract object ConciseContract

  #print(format(contract_instance.getGreeting()))

  print('Contract value:{}'.format(contract_instance.functions.getGreeting().call()))


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

相關文章