Skip to main content

Operation Flow

tip

Operation payloads are compatible with @airgap/beaon-sdk's specification

Send an operation to an entrypoint

Use the send method to send an operation:

const operationHash = await embed.send([
// ...
])

Let's add a new button that performs an entrypoint call (fulfill_ask)

src/app.tsx
export default function App() {
// ...
async function handleSend() {
try {
const operationHash = await kukaiEmbed.current!.send([
{
kind: "transaction",
source: userTezosAddress,
gas_limit: "7942",
storage_limit: "350",
amount: "1500000",
destination: "KT1MFWsAXGUZ4gFkQnjByWjrrVtuQi4Tya8G",
parameters: {
entrypoint: "fulfill_ask",
value: {
prim: "Pair",
args: [
{
int: "11000856"
},
{
prim: "Pair",
args: [
{
int: "1"
},
{
prim: "Pair",
args: [
{
prim: "None"
},
{
prim: "Pair",
args: [
{
prim: "None"
},
[]
]
}
]
}
]
}
]
}
}
}
])
} catch (error) {
console.log(error);
}
}

return (
<div className="App">
// ...
{!!user && <button onClick={handleSend}>Send Operation</button>}
</div>
);
}



Tracking Operations

When a pending operation is approved, kukai-embed returns an operationHash. At this point, the operation has been injected but its success is not guaranteed. Usually, successful operations are confirmed at least 5 seconds after injection.

There are two ways to track and verify an operationHash:

  1. Sending a GET request to api.tzkt.io/v1/operations
  2. Using tzkt events (SubscribeToOperations on api.tzkt.io/v1/ws)

The first option can be used for verifying older operations, while the second option allows for real-time operation tracking.

tip

In serverless environments, where socket connections might not be supported, operations can be tracked just by sending GET requests to api.tzkt.io/v1/operations, using short polling

Method 1: Sending a GET request

After retrieving the operationHash using the send method, send a get request to api.tzkt.io/v1/operations

const operationHash = await kukaiEmbed.current!.send(/* ... */)
// operation has been injected
// wait for at least 5 seconds before checking
const response = await fetch(`https://api.tzkt.io/v1/operations/${operationHash}`)

Successful operations contain a status field that is set to "applied"

Method 2: Using tzkt events

A SignalR connection needs to be established before using the send method in kukai-embed. Please visit the tzkt events page for more information.

Install the SignalR client:

yarn add @microsoft/signalr
# or
npm install @microsoft/signalr

Then start a connection and subscribe to SubscribeToOperations:

const connection = new signalR.HubConnectionBuilder()
.withUrl("https://api.tzkt.io/v1/ws")
.build();

async function init() {
// open connection
await connection.start();
// subscribe to account operations
await connection.invoke("SubscribeToOperations", {
address: "KT19kgnqC5VWoxktLRdRUERbyUPku9YioE8W", // replace the address
types: "transaction"
});
};

// auto-reconnect
connection.onclose(init);

connection.on("operations", (payload) => {
const isVerified = payload.status === "applied"
});

init();