Is there a way to externally listen to (contract-call? ...) calls on a contract?

117 views Asked by At

I have two Clarity contracts (lets call them A and B), and an application that listens to function calls on A, using the @stacks API client.

This works fine for when I manually call any function on A (using scripts or the Sandbox, initiating a transaction).

But if I am calling a function of A from contract B like so:

(as-contract (contract-call? .contract-A contract-A-function-name param1 param2)) 

Let's say contract-A-function-name is a simple function with just a (print) event.

This is successful, but there is no separate tx/event to listen to on contract A. This might be intended behaviour, but my question is nevertheless: Is there a way to know when contract-A's function was called this way?

1

There are 1 answers

0
Brice On

That's right, there is no event reported when a function is called, but there is an event for the print that you can find. You can query for events and get a response like this:

{
  "event_index": 1,
  "event_type": "smart_contract_log",
  "tx_id": "0x05ccc123db703a2808afaaf88b6b3240f14391d14fde701bd20d7206c9133af6",
  "contract_log": {
    "contract_id": "ST000000000000000000002AMW42H.bns",
    "topic": "print",
    "value": {
      "hex": "0x0c000000010a6174746163686d656e740c00000003106174746163686d656e742d696e646578010000000000000000000000000000028304686173680200000014b472a266d0bd89c13706a4132ccfb16f7c3b9fcb086d657461646174610c00000004046e616d65020000000a62696c616c7465737435096e616d6573706163650200000003627463026f700d0000000d6e616d652d7472616e736665720974782d73656e646572051a27b6e19aaa1880e842bc709b4130b347b1f2d7f2",
      "repr": "(tuple (attachment (tuple (attachment-index u643) (hash 0xb472a266d0bd89c13706a4132ccfb16f7c3b9fcb) (metadata (tuple (name 0x62696c616c7465737435) (namespace 0x627463) (op \"name-transfer\") (tx-sender STKVDRCTN8C81T22QHR9PG9GPD3V3WPQYBYFHPT4))))))"
    }
  }
}