我一直在阅读各种教程(其中许多已经过时,或者链接已经中断),以了解如何在ETH区块链中存储和检索简单的字符串或十六进制值。就我的目的(以及我正在开发的应用程序)而言,最好能够通过Python与区块链进行接口。
我试过使用web3和pyethereum,但没有取得多大成功。我得到的最深入的方法是使用下面的代码和web3接口。
我丢失了哪些部分,以及如何正确地存储和检索ETH块链上的值?
def eth_black_magic(hex_value):
web3 = Web3(HTTPProvider('http://localhost:8545')) # what URL should I point at?
user1 = 'xxx' # what goes here?
user2 = 'xxx' # what goes here?
transaction = {'from': user2, 'to':user1, 'data': hex_value}
transaction_hash = web3.eth.sendTransaction(transaction)发布于 2017-08-30 16:52:13
一种一般的方法看起来可能是:
uint public val说setVal(uint)Web3(...)contract.deploy()部署合同对于步骤1-3,remix可能是一个很好的选择。您可以在步骤4-7中使用web3.py。所有单独的步骤都应该存在文档和教程。
现在,您已经准备好了一个已部署的合同。您可以使用以下方法在python中获取和设置val:
contract.transact().setVal(1337)设置变量contract.call().val()获取变量发布于 2017-08-29 08:40:52
使用要以常量形式存储的值部署契约。
contract C {
string constant text = "abc";
function getMystr() constant returns (string) {
return mystr;
}
}可以通过调用getMystr()函数来检索该值。
https://ethereum.stackexchange.com/questions/25372
复制相似问题