EOS-EOSFactory
旨在成为一个完整的,完全记录的跨平台IDE,使用简单的命令行界面,你将能够:
- 启动私有 EOS testnet。
- 编译 EOS 智能合约。
- 通过单元测试运行它。
- 调整它直到你觉得它准备好了。
- 在 EOS 上部署它。
- 跨平台兼容性。
在EOSFactory中,我们使用Python与智能合约进行交互。但是,在内核里,我们的工具集由C++提供支持。
因此,EOSFactory由两层组成:
- 名称为teos的C++桥连接到运行私有testnet的EOS节点。
- 名称为Pyteos的Python封装器充当方便的人机界面。
开发周期
这就是智能合约开发周期的样子:
- 写一份智能合约(用EOS的原生C++编写)。
- 编写单元测试(在Python中)。
- 编译你的智能合约。
- 启动一个新的单节点testnet。
- 使用Bios合约和几个测试帐户初始化testnet。
- 部署智能合约。
- 运行单元测试。
- 下线testnet。
- 修改智能合约或单元测试并跳转到第3步。
在EOSFactory中,上述过程的每一步都由Python类和方法完全自动化。作为开发人员,你只提供创意部分,即智能合约和单元测试的内容。单元测试旨在用Python编写,而智能合约当然是用C++编写的。Visual Studio Code完美支持这两种语言。
build
git clone https://github.com/tokenika/eosfactory.git |
upgrade
cd eosfactory |
usage
python3 |
Create accounts
create_account("charlie", master) |
NOTE: If you don’t specify the account_name parameter in create_account(), a random name is applied, which is useful on a public testnet where extra restrictions apply.
However, if you want to assign a specific name to an account, you can still do it, for example:
create_account("charlie2", master, account_name="charlie4eos") |
Create reference to an existing contract
create an account which will host the contract:
create_account("host", master) |
And then create a reference to the contract by supplying the host account and the path to the folder where the contract is located, for example:
contract = Contract(host, "/Users/zhengjun/project/blockchain/EOS/contracts/mw-coin") |
Build the contract
这里不会覆盖 abi 文件,会拷贝到 build 目录下面,避免生成 abi 有问题。
contract.build() |
或者分开生成
contract.build_abi() |
Deploy the contract
查看代码,deploy 之后再次查看
contract.code() |
wallet 对象
create_wallet() |
Create the token
host.push_action( |
NOTE: The push_action method takes three arguments: the action’s name, the action’s arguments in JSON format and the accounts whose permission is needed, in this case master & host.
NOTE: If you want to see the actual transaction without broadcasting it, use the show_action method instead of push_action, for example:
host.show_action( |
Create more accounts
create_account("alice", master) |
Issue tokens
host.push_action( |
Transfer tokens
host.push_action( |
NOTE: As the third argument we pass the reference to the alice account to indicate that she is the one who authorized this action.
Check the contract table
host.table("accounts", alice) |
NOTE: The table() method takes two arguments: the name of the table as specified by the contract ABI and the scope within the contract in which the table is found.
Stop testnet and exit Python
stop() |
using with Visual Studio Code
- Create a new smart-contract VSC project
cd eosfactory
python3 utils/create_project.py foo_bar 01_hello_world --vsc
foo_bar 是要创建的合约的名字,01_hello_world 是模板,–vsc 会打开vscode
原来的 eosfactory 有些小地方不兼容 cdt 1.4.1 如果直接使用会无法编译。
下面提供了修改后的代码,已经在官网提了 PR,但是不知道什么时候合并,所以这里先提供一个可以用的。
https://github.com/tyler2018/eosfactory
注意需要在 c_cpp_properties.json 里面配置 includePath