Developers
Caduceus WebSocket Endpoints
eth_subscribe
9min
caduceus follows the evm specification, so api should be the same as the api for ethereum or other compliant evm blockchains a good place to see the full documentation is on the alchemy eth subscribe documentation but continue reading to understand the most important parts eth subscribe parameters eth subscribe takes an array value params which accepts two items in the array the first is the subscription name and the second is an optional data payload subscription name string the type of event you want to subscribe to (i e , newheads, logs, pendingtransactions, newpendingtransactions) this method supports the following subscription types newheads it fires a notification each time a new header is appended to the chain, including chain reorganizations logs it returns logs that are included in new imported blocks and match the given filter criteria pendingtransactions it returns full transactions that are sent to the network, marked as pending, and are sent from or to a certain address newpendingtransactions it returns the hash for all transactions that are added to the pending state and are signed with a key that is available in the node data object (optional) the arguments such as an address, multiple addresses, and topics note, only logs that are created from these addresses or match the specified topics will return logs returns result the hex encoded subscription id this id will be attached to all received events and can also be used to cancel the subscription using eth unsubscribe newheads the newheads subscription type emits an event any time a new header (block) is added to the chain, including during a chain reorganization request \> wscat c "wss\ //mainnet ws caduceus foundation" \# this will open up a connection and it will show the following message if \# successfully connected connected (press ctrl+c to quit) \> { "id" 1, "method" "eth subscribe", "params" \["newheads"] } response { "jsonrpc" "2 0", "method" "eth subscription", "params" { "result" { "difficulty" "0x15d9223a23aa", "extradata" "0xd983010305844765746887676f312e342e328777696e646f7773", "gaslimit" "0x47e7c4", "gasused" "0x38658", "logsbloom" "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "miner" "0xf8b483dba2c3b7176a3da549ad41a48bb3121069", "nonce" "0x084149998194cc5f", "number" "0x1348c9", "parenthash" "0x7736fab79e05dc611604d22470dadad26f56fe494421b5b333de816ce1f25701", "receiptroot" "0x2fab35823ad00c7bb388595cb46652fe7886e00660a01e867824d3dceb1c8d36", "sha3uncles" "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", "stateroot" "0xb3346685172db67de536d8765c43c31009d0eb3bd9c501c9be3229203f15f378", "timestamp" "0x56ffeff8", "transactionsroot" "0x0167ffa60e3ebc0b080cdb95f7c0087dd6c0e61413140e39d94d3468d7c9689f" }, "subscription" "0x9ce59a13059e417087c02d3236a0b1cc" } } logs setting the subscription name to logs is a great way to listen to events on a particular smart contract it however needs the following data field to be set it is an object with the following fields address topics an array of topic specifiers each topic specifier is either for every non null topic, a log will be emitted when activity associated with that topic occurs topic specifications \[] any topics allowed \[a] a in first position (and anything after) \[null, b] anything in first position and b in second position (and anything after) \[a, b] a in first position and b in second position (and anything after) \[\[a, b], \[a, b]] (a or b) in first position and (a or b) in second position (and anything after) to understand more about topics we suggest you read the api documentation of alchemy which explain it very well request \> wscat c "wss\ //mainnet ws caduceus foundation" \# this will open up a connection and it will show the following message if \# successfully connected connected (press ctrl+c to quit) \> {"jsonrpc" "2 0","id" 1, "method" "eth subscribe", "params" \["logs", {"address" "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "topics" \["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"]}]} response { "jsonrpc" "2 0", "method" "eth subscription", "params" { "subscription" "0x4a8a4c0517381924f9838102c5a4dcb7", "result" { "address" "0x8320fe7702b96808f7bbc0d4a888ed1468216cfd", "blockhash" "0x61cdb2a09ab99abf791d474f20c2ea89bf8de2923a2d42bb49944c8c993cbf04", "blocknumber" "0x29e87", "data" "0x00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000003", "logindex" "0x0", "topics" \["0xd78a0cb8bb633d06981248b816e7bd33c2a35a6089241d099fa519e361cab902"], "transactionhash" "0xe044554a0a55067caafd07f8020ab9f2af60bdfe337e395ecd84b4877a3d1ab4", "transactionindex" "0x0" } } } below you can find the explanation for individual properties of the response jsonrpc the jsonrpc property specifies the version of the json rpc protocol that is being used, which in this case is "2 0" method the method property specifies the method that was called, which in this case is eth subscription params the params property contains the parameters of the method call in this case, it contains a subscription property, which specifies the subscription identifier, and a result property, which contains the result of the subscription result the result property contains information about a specific transaction on the ethereum blockchain address the address property specifies the address from which this log originated blockhash the blockhash property specifies the hash of the block in which the transaction was included blocknumber the blocknumber property specifies the number of the block in which the transaction was included it is encoded as a hexadecimal string data contains one or more 32 bytes non indexed arguments of the log logindex the logindex property specifies the index or position of the log entry within the block it is encoded as a hexadecimal string topics the topics property is an array of 0 to 4 32 bytes topic hashes of indexed log arguments transactionhash the transactionhash property specifies the hash of the transaction transactionindex the transactionindex property specifies the index or position of the transaction within the block it is encoded as a hexadecimal string