您的位置:首页 > 其它

serpent语言的第一个智能合约

2016-12-08 19:56 405 查看
Linux安装In order to install the Serpent python library and executable do:
git clone https://github.com/ethereum/serpent.git $ cd serpent
$ git checkout develop
$ make && sudo make install
$ python setup.py install
You can install pyethereum itself as well:
$ git clone https://github.com/ethereum/pyethereum.git $ cd pyethereum
$ git checkout develop
$ pip install -r requirements.txt
$ python setup.py install
用serpent写的文件保存为.se文件。然后进去所在的文件夹。再进去python,然后比如说运行register.se
def register(key, value):
# Key not yet claimed
if not self.storage[key]:
self.storage[key] = value
return(1)
else:
return(0)  # Key already claimed

def ask(key):
return(self.storage[key]
进入pythony以后按下面运行,所有的前三句是一样的
>>> from ethereum import tester as t
>>> s = t.state()//initializes a new state (ie. a genesis block).
>>> c = s.abi_contract('namecoin.se')// creates a new contract, and creates an object in Python which represents it.
>>> c.register(0x67656f726765, 45)//注册kEY=0x67656`````
1
>>> c.register(0x67656f726765, 20)
0
>>> c.register(0x6861727279, 65)
1
>>> c.ask(0x6861727279)
65

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: