从部署的智能合约中读取数据:
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("ropsten.infura.io/<ApI 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 开发功能:kaifa873
contract_instance=w3.eth.contract(abi=abi,address=contract_address)
#Contract instance in concise mode