RPC over HTTP is inherently unsafe, as any browser tab may access your server. Because of this, any functionality that was deemed unsafe for public consumption is not available by default on the HTTP interface.
You have two options: you can either force enable the things you're missing via --rpcapi
, just make sure you're clear with the security consequences. The other and better solution is to do API requests via the IPC channel, which has all methods enabled by default.
For a full list of Geth 1.3.x management methods see https://github.com/ethereum/go-ethereum/wiki/Go-ethereum-management-API's . This list will be significantly expanded with the 1.4 release.
Filters work a little bit different. Filters require LOG
s to be emitted from an EVM execution (i.e. a contract). Solidity makes this easy for you by allowing you to fire event
s (compiled event
s generate LOG
s).
Let's take the following contract:
contract T {
event res(uint indexed out)
function echo(uint in) {
res(i);
}
}
When the method echo
is invoked on the contract it fires the solidity event res
. These events can be caught using the eth_newFilter
and queried using eth_getFilterChanges
.
When creating a filter for a specific event (e.g. res
) we need to derive the event signature first. Signatures are generated using the first 4 bytes of the keccak
hash of the event's definition (i.e. res(uint)
): keccak("res(uint)")
. This then becomes the first argument for the eth_newFilter
's topics.
Any of the arguments in the definition of the event that have the indexed
keyword (as in the example contract listed above) can also be used to filter on. Let's say we only want to catch events for the number 6, we would then construct the following JSON-RPC:
curl -X POST --data '{"jsonrpc":"2.0","method":"eth_newFilter","params":[{"address": "0xaddress", topics:["KECCAK_HASH", "0x6"], "fromBlock":"latest","toBlock":"latest"}],"id":2}' localhost:8545 {"id":2,"jsonrpc":"2.0","result":"0x0"}
Now whenever the method echo(6)
is invoked on the contract you'll be able to query the result using the eth_getFilterChanges
.
Please see the solidity docs on events for more information.
Best Answer
have a look at the documentation :
Over RPC (insecure solution)
to use it you need to enable the personal Api
geth --rpc --rpcapi "personal,eth,web3"
more details : https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_newaccount