How to register an effect
Effects are used to extend the ledger core functionalities by observing and reacting on events raised when a change occurs with ledger data.
We will register an effect which is triggered by an event with signal balance-received
, but only when wallet with handle bank1
receives a balance in usd
symbol. When triggered, the effect will execute webhook
action which sends a HTTP POST request with event payload to the endpoint defined in webhook action, or to the server defined in a bridge if the effect action schema if bridge
. We will assume that there is a local HTTP server which listens on http://localhost:3000/v2/effects/bank1-balance-received
endpoint.
Registering a webhook effect
Example in Node.js by using @minka/ledger-sdk
:
Or by using @minka/cli
:
Registering a bridge effect
Firstly, we need to setup a bridge in the ledger to receive an event when a balance is changed - received - in the system.
Via @minka/ledger-sdk
:
Or via @minka/cli
:
The bridge should implement at least events
trait to be able to receive effect calls.
Now we have our bridge, we can proceed and register the effect targeting the bridge created previously.
By using @minka/ledger-sdk
:
Or by using @minka/cli
:
After that, the bridge will start to receive those events at
POST http://localhost:3000/v2/effects/bank2-balance-received
.
Notice that bank2-balance-received
is the handle of the effect created, so the endpoint
on the other side should be registered with same value.
Related
How to handle effect webhook calls