马蹄链佛萨奇/泰山众筹阿凡达/众筹互助/智能合约流动性挖矿分红系统开发(开发详情)
Smart contract,in short,is a technology that digitizes the contract in our life and can be automatically executed by the program when a condition is met.For example,you made an agreement with me.We decided on reward and punishment measures,and then entered the agreement into the blockchain in the form of code.Once the agreed conditions are triggered,a program will automatically execute it,which is smart contract
从部署的智能合约中读取数据
在我们的合约中,有一个方法getGreeting()可以检索我们在区块链中添加的问候语。我们将使用web3.py调用此方法打开您的Python IDLE编辑器并使用以下代码创建一个新文件read.py。运行py read.py读取问候语。
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/<ApI Key here>"))
print(w3.isConnected())开发功能及流程I59模式2OO7开发3O69
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()))需求及案例:yy625019
print('Contract value:{}'.format(contract_instance.functions.getGreeting().call()))
导入的web3库和所有其他必需的模块
通过指向Ropsten Infura节点启动web3提供程序
通过指向abi和contract_Address创建合约实例(来自上一步)
调用getGreeting()方法并在控制台打印结果