当前位置: 首页 > 工具软件 > Serpent > 使用案例 >

serpent语言的第一个智能合约

丁慈
2023-12-01
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



 类似资料: