修改 config.ini
- access-control-allow-origin = * //解决跨域问题
- http-server-address = 0.0.0.0:8888 //接受任何IP的访问
修改 config.ini
surou@surou-C-H110M-K-Pro:~$ cleos get transaction 75b70df41828c9585c2e7b690c2a481ef4bd5733e775305bbb7bc01f5aa058c8
{
"id": "75b70df41828c9585c2e7b690c2a481ef4bd5733e775305bbb7bc01f5aa058c8",
"trx": null,
"block_time": "2000-01-01T00:00:00.000",
"block_num": 0,
"last_irreversible_block": 1314661,
"traces": []
}
修改 config.ini中filter-on = *
或者 nodeos启动时添加参数--filter-on "*"
重新发起transaction
获取新的transaction_id
。之前旧的transaction_id
无法获取
surou@surou-C-H110M-K-Pro:~$ cleos get transaction 6c0a755fc81eaa94baf679a2aced81ee913b2f4b98d939aeadce6f7889a7003e
{
"id": "6c0a755fc81eaa94baf679a2aced81ee913b2f4b98d939aeadce6f7889a7003e",
"trx": {
"receipt": {
"status": "executed",
"cpu_usage_us": 1668,
"net_usage_words": 17,
"trx": [
1,{
"signatures": [
"SIG_K1_KWDHq27a9rtwxerQi6TM5tDEerqbEcLiKJcL3hpBYHhGgtr5gKhsD91KskhCwPK6hH5jqhdbK2cn4tW7npwh5T7KmQtpEV"
],
"compression": "none",
"packed_context_free_data": "",
"packed_trx": "60a53d5b45295d4bfb8f000000000100a6823403ea3055000000572d3ccdcd01000040aa2b50ab4900000000a8ed32322c000040aa2b50ab490000000000ea3055884600000000000004454f53000000000b68656c6c6f20776f726c6400"
}
]
},
"trx": {
"expiration": "2018-07-05T04:58:08",
"ref_block_num": 10565,
"ref_block_prefix": 2415610717,
"max_net_usage_words": 0,
"max_cpu_usage_ms": 0,
"delay_sec": 0,
"context_free_actions": [],
"actions": [{
"account": "eosio.token",
"name": "transfer",
"authorization": [{
"actor": "dapp.exec",
"permission": "active"
}
],
"data": {
"from": "dapp.exec",
"to": "eosio",
"quantity": "1.8056 EOS",
"memo": "hello world"
},
"hex_data": "000040aa2b50ab490000000000ea3055884600000000000004454f53000000000b68656c6c6f20776f726c64"
}
],
"transaction_extensions": [],
"signatures": [
"SIG_K1_KWDHq27a9rtwxerQi6TM5tDEerqbEcLiKJcL3hpBYHhGgtr5gKhsD91KskhCwPK6hH5jqhdbK2cn4tW7npwh5T7KmQtpEV"
],
"context_free_data": []
}
},
"block_time": "2018-07-05T04:57:09.000",
"block_num": 1321304,
"last_irreversible_block": 1321453,
"traces": [{
"receipt": {
"receiver": "eosio.token",
"act_digest": "243d8d4afdb3b52f610f27efa55efac1e600e50bb8bc488dd8651dca3c242f07",
"global_sequence": 1321588,
"recv_sequence": 73,
"auth_sequence": [[
"dapp.exec",
111
]
],
"code_sequence": 1,
"abi_sequence": 1
},
"act": {
"account": "eosio.token",
"name": "transfer",
"authorization": [{
"actor": "dapp.exec",
"permission": "active"
}
],
"data": {
"from": "dapp.exec",
"to": "eosio",
"quantity": "1.8056 EOS",
"memo": "hello world"
},
"hex_data": "000040aa2b50ab490000000000ea3055884600000000000004454f53000000000b68656c6c6f20776f726c64"
},
"elapsed": 1032,
"cpu_usage": 0,
"console": "",
"total_cpu_usage": 0,
"trx_id": "6c0a755fc81eaa94baf679a2aced81ee913b2f4b98d939aeadce6f7889a7003e",
"inline_traces": [{
"receipt": {
"receiver": "dapp.exec",
"act_digest": "243d8d4afdb3b52f610f27efa55efac1e600e50bb8bc488dd8651dca3c242f07",
"global_sequence": 1321589,
"recv_sequence": 38,
"auth_sequence": [[
"dapp.exec",
112
]
],
"code_sequence": 1,
"abi_sequence": 1
},
"act": {
"account": "eosio.token",
"name": "transfer",
"authorization": [{
"actor": "dapp.exec",
"permission": "active"
}
],
"data": {
"from": "dapp.exec",
"to": "eosio",
"quantity": "1.8056 EOS",
"memo": "hello world"
},
"hex_data": "000040aa2b50ab490000000000ea3055884600000000000004454f53000000000b68656c6c6f20776f726c64"
},
"elapsed": 445,
"cpu_usage": 0,
"console": "",
"total_cpu_usage": 0,
"trx_id": "6c0a755fc81eaa94baf679a2aced81ee913b2f4b98d939aeadce6f7889a7003e",
"inline_traces": []
},{
"receipt": {
"receiver": "eosio",
"act_digest": "243d8d4afdb3b52f610f27efa55efac1e600e50bb8bc488dd8651dca3c242f07",
"global_sequence": 1321590,
"recv_sequence": 1321418,
"auth_sequence": [[
"dapp.exec",
113
]
],
"code_sequence": 1,
"abi_sequence": 1
},
"act": {
"account": "eosio.token",
"name": "transfer",
"authorization": [{
"actor": "dapp.exec",
"permission": "active"
}
],
"data": {
"from": "dapp.exec",
"to": "eosio",
"quantity": "1.8056 EOS",
"memo": "hello world"
},
"hex_data": "000040aa2b50ab490000000000ea3055884600000000000004454f53000000000b68656c6c6f20776f726c64"
},
"elapsed": 95,
"cpu_usage": 0,
"console": "",
"total_cpu_usage": 0,
"trx_id": "6c0a755fc81eaa94baf679a2aced81ee913b2f4b98d939aeadce6f7889a7003e",
"inline_traces": []
}
]
},{
"receipt": {
"receiver": "dapp.exec",
"act_digest": "243d8d4afdb3b52f610f27efa55efac1e600e50bb8bc488dd8651dca3c242f07",
"global_sequence": 1321589,
"recv_sequence": 38,
"auth_sequence": [[
"dapp.exec",
112
]
],
"code_sequence": 1,
"abi_sequence": 1
},
"act": {
"account": "eosio.token",
"name": "transfer",
"authorization": [{
"actor": "dapp.exec",
"permission": "active"
}
],
"data": {
"from": "dapp.exec",
"to": "eosio",
"quantity": "1.8056 EOS",
"memo": "hello world"
},
"hex_data": "000040aa2b50ab490000000000ea3055884600000000000004454f53000000000b68656c6c6f20776f726c64"
},
"elapsed": 445,
"cpu_usage": 0,
"console": "",
"total_cpu_usage": 0,
"trx_id": "6c0a755fc81eaa94baf679a2aced81ee913b2f4b98d939aeadce6f7889a7003e",
"inline_traces": []
},{
"receipt": {
"receiver": "eosio",
"act_digest": "243d8d4afdb3b52f610f27efa55efac1e600e50bb8bc488dd8651dca3c242f07",
"global_sequence": 1321590,
"recv_sequence": 1321418,
"auth_sequence": [[
"dapp.exec",
113
]
],
"code_sequence": 1,
"abi_sequence": 1
},
"act": {
"account": "eosio.token",
"name": "transfer",
"authorization": [{
"actor": "dapp.exec",
"permission": "active"
}
],
"data": {
"from": "dapp.exec",
"to": "eosio",
"quantity": "1.8056 EOS",
"memo": "hello world"
},
"hex_data": "000040aa2b50ab490000000000ea3055884600000000000004454f53000000000b68656c6c6f20776f726c64"
},
"elapsed": 95,
"cpu_usage": 0,
"console": "",
"total_cpu_usage": 0,
"trx_id": "6c0a755fc81eaa94baf679a2aced81ee913b2f4b98d939aeadce6f7889a7003e",
"inline_traces": []
}
]
}
EOS资源系统由RAM,CPU,NET组成。数据存储需要消耗RAM,账号交易需要使用CPU和NET。一个EOS账号创建的时候可以通过购买和抵押来获取资源,费用由主账号支付。如果创建账号时并未购买资源,则需要通过其他账号购买或者进行抵押,因为购买和抵押本身就是一种交易行为需要消耗资源。
RAM是运行时的内存。在EOSIO系统中,数据存储在区块链中要消耗该资源,是DApp开发时必须的资源。
网络带宽以过去3天的平均消耗量为单位进行测量,单位是字节如KB。每次发送操作或事务时都会暂时消耗网络带宽,但随着时间的推移会减少到0。抵押的EOS越多,网络带宽可以使用得越多。 可以随时赎回EOS,但是有三天左右的赎回期。
CPU带宽以过去3天的平均消耗(以微秒ms为单位)来衡量。 当您发送操作或事务时,CPU带宽会暂时消耗,但随着时间的推移会减少到0。事务运行时间越长,它将消耗的CPU带宽就越多。 可以随时赎回EOS,但是有三天左右的赎回期。
资源操作
//账号资源查看
cleos get account ${account}
//${account1}为支付账号,${account2}获得账号
//ram购买
cleos system buyram ${account1} ${account2} "0.0001 EOS"
//ram销售,最多能售出的数量limit - used
cleos system sellram ${account1} 68718 -p ${account1}
//抵押EOS,获得CPU带宽和NET带宽
cleos system delegatebw ${account1} ${account2} '0.1000 EOS' '0.1000 EOS' -p ${account1}
//取消抵押
cleos system undelegatebw ${account1} ${account2} '1 EOS' '1 EOS' -p ${account1}
转载自:blockflow.net
这里主要是要教会大家如果将自己公钥里面的账户名转给其他人。能转出给另外一个公钥就可以实现线下交易,线上转账户名了。
代码如下:
#转移active权限
cleos push action eosio updateauth '{"permission":"active","parent":"owner","account":"你要转移的帐号","auth": {"accounts": [], "waits": [], "keys": [{"key": "EOS开头的对方的公钥", "weight": 1}], "threshold": 1}}' -p 你要转移的帐号@active
#转移owner权限
cleos push action eosio updateauth '{"permission":"owner","parent":"","account":"你要转移的帐号","auth": {"accounts": [], "waits": [], "keys": [{"key": "EOS开头的对方的公钥", "weight": 1}], "threshold": 1}}' -p 你要转移的帐号@owner
如果是网络情况报错可能是没有连接上主网,则改为:
#转移active权限
cleos -u http://mainnet.eoswz.com push action eosio updateauth '{"permission":"active","parent":"owner","account":"你要转移的帐号","auth": {"accounts": [], "waits": [], "keys": [{"key": "EOS开头的对方的公钥", "weight": 1}], "threshold": 1}}' -p 你要转移的帐号@active
#转移owner权限
cleos -u http://mainnet.eoswz.com push action eosio updateauth '{"permission":"owner","parent":"","account":"你要转移的帐号","auth": {"accounts": [], "waits": [], "keys": [{"key": "EOS开头的对方的公钥", "weight": 1}], "threshold": 1}}' -p 你要转移的帐号@owner
注意!
这里可能会提示一些报错。例如:
#CPU不够
Error 3080004: transaction exceeded the current CPU usage limit imposed on the transaction
Error Details:
billed CPU time (574 us) is greater than the maximum billable CPU time for the transaction (0 us)
#.NET不够
Error 3080002: transaction exceeded the current network usage limit imposed on the transaction
Error Details:
net usage of transaction is too high: 160 > 0
这是因为你在建立这个账户名的时候,账户名下没有足够的资源导致。所以只需要其他有资源的账户给这个账户转入一些资源就可以了。
web3j过滤器提供以太坊网络发生的某些事件的通知,对java和安卓程序员来说很有用。在Ethereum以太坊中支持三类过滤器:
WebSocket
连接到Geth,否则通过JSON-RPC API来处理过滤器是一个繁琐的过程,这里需要轮询以太坊客户端,以便了解HTTP和IPC所请求的实时同步特征,是否有任何新的更新到你的过滤器。此外,块和交易过滤器只提供交易或区块链hash值,因此需要进一步的请求来获得hash对应的实际交易或块。web3j的过滤器解决了这些问题,因此你有一个完全异步的基于事件的API来处理过滤器。它使用RXJava的可观测性Observables,它提供了与事件协同工作的一致API,这有助于通过功能组合将JSON-RPC调用链接在一起。
注:Infura
不支持过滤器。
接收所有新块把它们添加到区块链(false参数指定我们只需要块就ok,而不需要嵌入交易):
Subscription subscription = web3j.blockObservable(false).subscribe(block -> {
...
});
接收所有新交易,把它们添加到块链:
Subscription subscription = web3j.transactionObservable().subscribe(tx -> {
...
});
接收所有待提交交易并提交到网络(即在它们被分组在一起之前):
Subscription subscription = web3j.pendingTransactionObservable().subscribe(tx -> {
...
});
不再需要的时候取消订阅unsubscribe
:
subscription.unsubscribe();
另外还提供了其他回调,它们简单地提供了块或交易hash,这些细节涉及Web3JRX接口。
webjs还提供用于再现块和交易历史的过滤器。
从区块链再现一系列块:
Subscription subscription = web3j.replayBlocksObservable(
<startBlockNumber>, <endBlockNumber>, <fullTxObjects>)
.subscribe(block -> {
...
});
再现包含在一个块范围内的单个交易:
Subscription subscription = web3j.replayTransactionsObservable(
<startBlockNumber>, <endBlockNumber>)
.subscribe(tx -> {
...
});
也可以获得Web3J再现最新的块,并在你看过后提供通知(通过提交Observable
):
Subscription subscription = web3j.catchUpToLatestBlockObservable(
<startBlockNumber>, <fullTxObjects>, <onCompleteObservable>)
.subscribe(block -> {
...
});
或者,也可以在你再现最新的块后,通知新创建的后续块:
Subscription subscription = web3j.catchUpToLatestAndSubscribeToNewBlocksObservable(
<startBlockNumber>, <fullTxObjects>)
.subscribe(block -> {
...
});
如上所述,并包含在块内的交易:
Subscription subscription = web3j.catchUpToLatestAndSubscribeToNewTransactionsObservable(
<startBlockNumber>)
.subscribe(tx -> {
...
});
所有上述过滤器都是通过Web3JRX接口导出的。
主题过滤器捕获在网络中发生的以太坊虚拟机(EVM)事件的细节。这些事件是由智能合约创建的,并存储在与智能合约相关联的交易日志中。
solidity文档提供了EVM事件的良好概述。
使用EthFilter类型指定希望应用于过滤器的主题。这可以包括希望应用过滤器的智能合约的地址。你还可以提供特定的主题进行筛选。其中单个主题表示智能合约上的索引参数:
EthFilter filter = new EthFilter(DefaultBlockParameterName.EARLIEST,
DefaultBlockParameterName.LATEST, <contract-address>)
[.addSingleTopic(...) | .addOptionalTopics(..., ...) | ...];
然后可以使用类似于上面的块和交易过滤器的语法创建该过滤器:
web3j.ethLogObservable(filter).subscribe(log -> {
...
});
过滤器主题只能引用索引的Solidity事件参数。不可能对非索引事件参数进行筛选。此外,对于可变长度数组类型(如字符串和字节)的任何索引事件参数,它们的值的Keccak-256
hash 存储在EVM日志上。不可能使用它们的全部值来存储或筛选。
如果创建一个没有与之相关联的主题的过滤器实例,则在网络中发生的所有EVM事件都将由过滤器捕获。
除了send()
和sendAsync
之外,所有JSON-RPC方法在web3j中都实现了支持observable()方法来创建可观察的异步执行请求。这使得将JSON-RPC调用组合成新的函数是非常容易和直接的。
例如, blockObservable本身由许多单独的JSON-RPC调用组成:
public Observable<EthBlock> blockObservable(
boolean fullTransactionObjects, long pollingInterval) {
return this.ethBlockHashObservable(pollingInterval)
.flatMap(blockHash ->
web3j.ethGetBlockByHash(blockHash, fullTransactionObjects).observable());
}
在这里,我们首先创建一个可观察的,它提供每个新创建的块的块哈希的通知。然后,我们使用flatMap
调用ethGetBlockByHash
,以获得完整的块细节,这是传递给可观察者的订阅服务器的细节。
请参阅ObservableIT,进一步举例说明。
对于使用手动筛选器API的演示,可以查看EventFilterIT。
转载自汇智网。这里是原文