iost 私有链搭建与学习
problem
account not exist
iwallet account create qyvlik --server localhost:30002 -a admin
Connecting to server localhost:30002 ...
ERROR: account not exist
在指定 admin
创建账户时,提示 account not exist
,一般是指 admin
不在 iwallet
中,请确保执行了如下命令:
iwallet account import admin 2yquS3ySrGWPEKywCPzX4RTJugqRh7kJSo5aehsLYPEWkUxBWA39oMrZ7ZxuM4fgyXYs2cPwh5n8aNNpH5x2VyK1
expiration should be in (0, 90]
iwallet \
--expiration 10000 --gas_limit 1000000 --gas_ratio 1 \
--server localhost:30002 \
--account admin \
--amount_limit '*:unlimited' \
publish helloworld.js helloworld.abi
ERROR: expiration should be in (0, 90]
iost 官方的部署合约例子中,expiration
是 10000
,但是执行后报 expiration should be in (0, 90]
, expiration
的取值是从 1
到 90
,指定为 --expiration 90
即可,修复的命令如下:
iwallet \
--expiration 90 --gas_limit 1000000 --gas_ratio 1 \
--server localhost:30002 \
--account admin \
--amount_limit '*:unlimited' \
publish helloworld.js helloworld.abi
prepare contract: contract iost.gas not found
iost 官方文档给的质押合约是错误的,gas.iost
才是正确的合约
iwallet --server 127.0.0.1:30002 --account admin call 'gas.iost' 'pledge' '["admin","qyvlik","100"]'
使用 iwallet compile
生成 abi 文件
iwallet compile example.js
生成的 abi 文件是 example.js.abi
使用合约转账
使用合约进行资金操作时,需要在 abi
文件中,每个导出的函数都有一个 amountLimit
,如果 函数涉及到了资金操作,需要在 amountLimit
字段添加 [{ "token":"iost", "val":"100" }]
,其中 token
是资金操作的币种,val
是最多可以操作的金额,可以设置成 unlimited
,合约以及 abi 参考如下:
class TestTransfer {
init() {}
can_update(data) {
return blockchain.requireAuth(blockchain.contractOwner(), "active");
}
send(amount, to) {
blockchain.transfer(tx.publisher, to, amount, "");
}
};
module.exports = TestTransfer;
{
"lang": "javascript",
"version": "1.0.0",
"abi": [
{
"name": "can_update",
"args": [
"string"
],
"amountLimit": [],
"description": ""
},
{
"name": "send",
"args": [
"string",
"string"
],
"amountLimit": [
{
"token": "iost",
"val": "100"
}
],
"description": ""
}
]
}
IOSTCrypto.sha3
IOSTCrypto.sha3
内部使用的是 sha256
,返回的结果是 base58
编码
转账提示 VerifyError publisher error
转账的 memo 带有中文,提示 VerifyError publisher error
,例如:
{"code":2,"message":"VerifyError publisher error"}
请更新官方 iost-official/java-sdk 到版本 3.0.6
,或者使用非官方的 maven 依赖qyvlik/io.iost-java-sdk:
<dependency>
<groupId>io.github.qyvlik</groupId>
<artifactId>io.iost-java-sdk</artifactId>
<version>broker-v3.0.6</version>
</dependency>
使用谷歌浏览器插件 iwallet 报 TimeError
error: {"code":2,"message":"TimeError"}
iost 对应的报错代码 tx_pool.go#L258。
解决方式是
- 备份好私钥后
- 退出谷歌浏览器
- 卸载谷歌浏览器的 iwallet 插件
- 然后重新安装 iwallet 插件
- 再重新导入私钥
invalid contract version
iost 测试链节点报 invalid contract version
,具体报错如下:
Error 2019-04-09 01:56:27.855 abi.go:81 invalid contract version: token.iost 1.0.3, please check `Monitor.prepareContract`
Warn 2019-04-09 01:56:27.855 isolator.go:246 isolator run action Action{Contract: system.iost, ActionName: updateNativeCode, Data: ["token.iost","1.0.3",""]}
failed, status &{4 running action Action{Contract: system.iost, ActionName: updateNativeCode, Data: ["token.iost","1.0.3",""]}
error: invalid contractID or version}, will rollback
Error 2019-04-09 01:56:27.856 pob.go:358 verify block failed, blockNum:8114577, blockHash:2oiwCLHGjfW8yTCBNz3WmHV6ZsaQiYkVZAHXZsEtd9iF. err=receipt not match, status not same: &{0 } != &{4 running action Action{Contract: system.iost, ActionName: updateNativeCode, Data: ["token.iost","1.0.3",""]}
error: invalid contractID or version}
txHash:"s\267\313&\245\007\224\003s\004\253l\022\364W2\".\327\026\254\335-vb\341w\"\332\004\256\204" gasUsage:456900 status:<> returns:"[]"
txHash:"s\267\313&\245\007\224\003s\004\253l\022\364W2\".\327\026\254\335-vb\341w\"\332\004\256\204" gasUsage:357000 status:<code:4 message:"running action Action{Contract: system.iost, ActionName: updateNativeCode, Data: [\"token.iost\",\"1.0.3\",\"\"]}\n error: invalid contractID or version" >
Warn 2019-04-09 01:56:27.856 pob.go:181 received sync block error, err:receipt not match, status not same: &{0 } != &{4 running action Action{Contract: system.iost, ActionName: updateNativeCode, Data: ["token.iost","1.0.3",""]}
error: invalid contractID or version}
txHash:"s\267\313&\245\007\224\003s\004\253l\022\364W2\".\327\026\254\335-vb\341w\"\332\004\256\204" gasUsage:456900 status:<> returns:"[]"
txHash:"s\267\313&\245\007\224\003s\004\253l\022\364W2\".\327\026\254\335-vb\341w\"\332\004\256\204" gasUsage:357000 status:<code:4 message:"running action Action{Contract: system.iost, ActionName: updateNativeCode, Data: [\"token.iost\",\"1.0.3\",\"\"]}\n error: invalid contractID or version" >
Info 2019-04-09 01:56:29.022 sync.go:158 Syncing block in [8114555 8115554]...
Info 2019-04-09 01:56:31.067 sync.go:158 Syncing block in [8114555 8115554]...
问题原因是 iost-node 版本比较低。解决方式是,升级 iost-node。
execution kill
iost-node 同步区块日志报 execution kill
,可能原因是磁盘不是 SSD 或者 CPU 频率比较低,升级磁盘到 SSD 或者 CPU 规格。