Subscribe to account events
You can call the event.account operation to subscribe to account events.
Request parameters
The following parameters are encapsulated and passed in as an object.
| Name | Required | Type | Description |
|---|---|---|---|
| to | true | string | The target account. |
Examples
// Create an event instanceconst contractEvent = chain.event.contract({to: 'first'}, (err, data) => {console.log(data)})// Register the event callbackcontractEvent.on((err, data) => {console.log(data)})// Update the contract codechain.ctr.contract('first').update(bytecode, {}, (err, contract, data) => {})
Cancel the subscription of account events
You can call the accountEvent.close operation to cancel the subscription of account events. This operation does not require any request parameters.
Examples
// Create an event instanceconst accountEvent = chain.event.account({to: 'Tester001'}, (err, data) => {console.log(data)})// Cancel the eventaccountEvent.close((err, data) => {console.log(data)})
Subscribe to contract events
You can call the event.contract operation to subscribe to contract events.
Request parameters
The following parameters are encapsulated and passed in as an object.
| Name | Required | Type | Description |
|---|---|---|---|
| to | true | string | The hash or name of the target contract. |
Examples
// Create an event instanceconst contractEvent = chain.event.contract({to: 'first'}, (err, data) => {console.log(data)})// Register the event callbackcontractEvent.on((err, data) => {console.log(data)})// Update the contract codechain.ctr.UpdateContract({to: 'first',data: {code: bytecode}}, (err, data, rlpData) => {})
Unsubscribe contract events
You can call the contractEvent.close operation to unsubscribe account events. This operation does not require any request parameters.
Examples
// Create an event instanceconst contractEvent = chain.event.contract({to: 'first'}, (err, data) => {console.log(data)})// Unsubscribe the eventcontractEvent.close((err, data) => {console.log(data)})
Subscribe to topic events
You can call the event.topic operation to subscribe to topic events.
Request parameters
The following parameters are encapsulated and passed in as an object.
| Name | Required | Type | Description |
|---|---|---|---|
| to | true | string | The target topic. |
Examples
// Create an event instanceconst topicEvent = chain.event.topic({to: 'create_account'}, (err, data) => {console.log(data)})// Register the event callbacktopicEvent.on((err, data) => {console.log(data)})// Run CreateAccount to trigger the create_account topic eventchain.ctr.CreateAccount({from: 'Tester001',to: 'Tester002',data: {recover_key: '0xf5e50510a04a3f659a0e89f2063f79f8c1aed5ddaab6420ac47700020d9889dc14dae4dc9843c88d8222167095d9e6ce052e8a19cbc737c3f3cddf66409dbb0a',auth_key: '0xf5e50510a04a3f659a0e89f2063f79f8c1aed5ddaab6420ac47700020d9889dc14dae4dc9843c88d8222167095d9e6ce052e8a19cbc737c3f3cddf66409dbb0a',auth_weight: 100}}, (err, data) => {})
Unsubscribe topic events
You can call the topicEvent.close operation to unsubscribe topic events. This operation does not require any request parameters.
Examples
// Create an event instanceconst topicEvent = chain.event.topic({to: 'create_account'}, (err, data) => {console.log(data)})// Unsubscribe the eventtopicEvent.close((err, data) => {console.log(data)})
Subscribe to block events
You can call the event.block operation to subscribe to contract events. This operation requires no request parameters.
Examples
// Create an event instanceconst blockEvent = chain.event.block({}, (err, data) => {console.log(data)})// Register the event callback to trigger the event while generating the blockblockEvent.on((err, data) => {console.log(data)})
Unsubscribe block events
You can call the blockEvent.close operation to unsubscribe topic events. This operation does not require any request parameters.
Examples
// Create an event instanceconst blockEvent = chain.event.block({}, (err, data) => {console.log(data)})// Unsubscribe the eventblockEvent.close((err, data) => {console.log(data)})