DAPP/FDF互助模式系統(tǒng)開發(fā)詳細(xì),DAPP/FDF互助開發(fā)源碼邏輯
什么是DApp
“DApp”代表去中心化應(yīng)用程序。與傳統(tǒng)應(yīng)用程序一樣,去中心化應(yīng)用程序也有前端(客戶端)和后端(服務(wù)器端)。DApp的用戶界面可以用任何語言編寫(就像傳統(tǒng)應(yīng)用程序一樣),并且可以調(diào)用其后端。那么,Dapps與傳統(tǒng)應(yīng)用程序有何不同?DApp的后端代碼運行在分散的對等網(wǎng)絡(luò)(即區(qū)塊鏈)上。您可能聽說過BitTorrent、Tor、Popcorn Time——它們是在點對點網(wǎng)絡(luò)上運行但不在區(qū)塊鏈上運行的DApp。
Dapps開發(fā)包括三個簡單的步驟:
在區(qū)塊鏈網(wǎng)絡(luò)上部署智能合約
從部署的智能合約中讀取數(shù)據(jù)
將交易發(fā)送到部署的智能合約
智能合約
Solidity是編寫智能合約最常用的語言,它編譯為可以在節(jié)點上運行的以太坊虛擬機(jī)上執(zhí)行的字節(jié)碼。
pragma solidity^0.5.7;
contract greeter{開發(fā)案例設(shè)計I35模式7O98開發(fā)O7I8
string greeting;
function greet(string memory _greeting)public{
greeting=_greeting;
}
function getGreeting()public view returns(string memory){
return greeting;
}需求及模式:MrsFu123
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("https://ropsten.infura.io/v3/<API key>"))#modify
print(w3.isConnected())
contract_address=Web3.toChecksumAddress("<Deployed Contract Address here>")#modify
key="<Private key with 0x prefix here>"#modify
acct=w3.eth.account.privateKeyToAccount(key)
account_address=acct.address
#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)
tx=contract_instance.functions.greet("Hello all my goody people").buildTransaction({'nonce':w3.eth.getTransactionCount(account_address)})
#Get tx receipt to get contract address
signed_tx=w3.eth.account.signTransaction(tx,key)
#tx_receipt=w3.eth.getTransactionReceipt(tx_hash)
hash=w3.eth.sendRawTransaction(signed_tx.rawTransaction)
print(hash.hex())