Post
Share your knowledge.
Is there an easy way to track publish transactions?
Is there an easy way to track publish transactions? I could stream transactions and look for publish commands but if there's an option to filter in the node that would be preferred.
- Sui
- SDKs and Developer Tools
Answers
5Yes, there are a couple of ways to track publish transactions in Sui. Here's a breakdown:
1. Streaming Transaction Events:
- Streaming is the most flexible approach as you can monitor transactions as they are published and processed on the network. You can stream the transactions and filter for
publish
commands within the events. - You can use the Sui JSON-RPC API or WebSocket to subscribe to the transaction events. Specifically, the
onTransaction
oronEvent
RPC methods would give you the transaction details in real-time.
You can then filter for Publish
events by looking at the transaction type, as a publish transaction will include a specific Publish
type command that you can match.
Here's an example in TypeScript using Sui SDK to stream and filter for publish transactions:
import { JsonRpcProvider } from '@mysten/sui.js';
const provider = new JsonRpcProvider('https://fullnode.devnet.sui.io');
async function subscribeToPublishTransactions() {
const subscription = provider.subscribeTransaction((tx) => {
if (tx.type === 'publish') {
console.log('Publish Transaction Detected:', tx);
}
});
// To stop streaming
// subscription.unsubscribe();
}
subscribeToPublishTransactions();
2. Filtering on Node Level:
Unfortunately, as of now, the Sui node does not provide a direct way to filter for specific transaction types (like publish
) on the node-side via the RPC. You would need to filter these transactions at the application level, as shown above, by inspecting the type or command within the transaction data.
3. Transaction Status Endpoint:
Another option is to use the getTransaction
endpoint of the JSON-RPC API. After publishing a transaction, you can poll this endpoint for the status of the transaction and check if it is a publish
type.
Conclusion:
- Streaming is the easiest and most flexible way to track
publish
transactions in real-time, as it lets you monitor all types of transactions and filter forpublish
events directly. - As of now, there is no built-in filtering for
publish
transactions on the node-side. Filtering must be done on the client-side after receiving the transaction events.
Track Publish Transactions Easily
- Use
suix_queryTransactionBlocks
with filter:
curl -X POST https://fullnode.mainnet.sui.io \
-H 'Content-Type: application/json' \
-d '{
"jsonrpc": "2.0",
"method": "suix_queryTransactionBlocks",
"params": [{
"MoveFunction": "0x2::package::publish"
}, null, 10]
}'
- Stream via WebSocket (real-time):
const client = new SuiClient({ url: 'wss://fullnode.mainnet.sui.io' });
client.subscribeEvent({
filter: { MoveEventType: '0x2::package::PublishEvent' },
onMessage: (event) => console.log('Published:', event)
});
Yes, you can track publish transactions in a more efficient way by leveraging Sui’s transaction filtering APIs and event subscription mechanisms, though with some limitations depending on the node setup. The most straightforward approach is to subscribe to MoveModulePublished
events emitted when a package is published. This avoids scanning every transaction manually.
To do this, you can use the suix_queryEvents
RPC method with an event filter like:
{
"jsonrpc": "2.0",
"id": 1,
"method": "suix_queryEvents",
"params": [
{
"MoveModule": {
"package": "0x0000000000000000000000000000000000000002",
"module": "package"
}
},
null,
10,
null
]
}
Or more generally, just filter by the event type MoveModulePublished
without requiring a specific package or module. Note that not all fullnodes index events well unless configured as archive nodes.
If you're building an indexer or stream, you can also track transaction blocks using sui_getTransactionBlock
or sui_queryTransactionBlocks
and filter by the Publish
transaction kind.
For a more scalable solution, set up a Sui fullnode with event indexing enabled and use the --enable-event-db
flag in your node config. This significantly improves performance for event queries.
You can find full documentation on this here: https://docs.sui.io/build/events and https://docs.sui.io/sui-jsonrpc.
1. Direct gRPC Filter (Fastest)
# Filter publishes only
grpcurl -plaintext -d '{
"filter": {
"MoveFunction": "0x2::package::publish"
}
}' localhost:9000 sui.rpc.v2.Read/QueryTransactionBlocks
2. WebSocket (Real-time)
const client = new SuiClient({ url: 'wss://fullnode.mainnet.sui.io' });
const unsubscribe = client.subscribeEvent({
filter: { MoveEventType: '0x2::package::PublishEvent' },
onMessage: (event) => console.log('New publish:', event)
});
3. Explorer Shortcut
- Suiscan: https://suiscan.xyz/mainnet/packages
- Sui Vision: Filter by "Publish" transaction type
Node Config (Optional)
Add to fullnode.yaml
for publish-specific indexing:
event-handlers:
- event-type: publish
sink:
type: webhook
url: "your-webhook-url"
Why This Works
- Publish transactions always use
0x2::package::publish
- The
PublishEvent
contains all metadata (package ID, sender, etc.)
For bulk historical data, use:
sui-tool query-tx --module package --function publish --limit 100
Yes, there are easier ways to track publish transactions in the Sui network without having to stream all transactions and manually filter them. You can leverage the Sui RPC API to query and filter transactions, which can help you directly track publish
commands without dealing with unnecessary transaction noise.
1. Using get_transactions
RPC Endpoint (with Filters)
The Sui RPC API provides a get_transactions
endpoint that allows you to filter transactions based on various parameters, including the type of transaction you're interested in. To track publish transactions, you can filter based on the MoveCall
transaction type and look for specific commands that correspond to publishing a Move module.
Example: Filter Transactions by Type
You can make a request to filter for publish transactions by checking for MoveCall
transactions with specific function calls (those related to publishing). Here's how you could structure your query:
GET /v1/transactions?Filter[TransactionType]=MoveCall&Filter[MoveFunctionName]=publish
This would help you to specifically query transactions that are related to publishing a Move module, filtering out unnecessary ones.
2. Transaction Streams with Filters
You can stream transactions using the Sui WebSocket API or via long-polling with the RPC to get live transaction updates. If you do this, filtering at the node-level for publish transactions might be more complicated, but you can still stream the transactions and filter them on the client side using the following approach:
- Stream the transactions using the WebSocket API.
- Filter for transactions that contain
MoveCall
functions related to publishing, or the specific address related to the contract being published.
Here's an example of a transaction stream query (pseudo-code for a WebSocket):
const socket = new WebSocket("ws://localhost:5001");
socket.onmessage = function(event) {
const txData = JSON.parse(event.data);
if (txData.type === "MoveCall" && txData.function === "publish") {
console.log("Publish Transaction Detected:", txData);
}
};
This approach allows for real-time tracking of publish transactions.
3. Sui Explorer (for Visual Tracking)
For non-programmatic tracking, you could use the Sui Explorer to monitor transactions in a visual interface. Sui Explorer allows you to search for specific types of transactions, including Move module publishing. While this isn't automatic, it can be useful for quick checks during development or testing.
- Sui Explorer: Sui Explorer
4. Monitor the publish
Event (If Available)
If there’s an event specifically related to publishing, like PublishEvent
, you can directly listen to it (using event-based functionality) in your application, if supported by the Sui node or blockchain framework. While this might not be available out-of-the-box, future implementations or community-built solutions could add this feature.
5. Automate the Tracking with Periodic Polling
For periodic tracking of published transactions, you can use the get_transactions
endpoint at regular intervals to search for newly published modules. This avoids continuous streaming but gives you frequent updates:
use reqwest::blocking::get;
use serde_json::Value;
fn fetch_transactions() -> Result<Value, reqwest::Error> {
let url = "http://localhost:5001/v1/transactions?Filter[TransactionType]=MoveCall&Filter[MoveFunctionName]=publish";
let response = get(url)?;
let json: Value = response.json()?;
Ok(json)
}
This can be used in a backend system that checks periodically for new publish
transactions.
Summary:
- RPC Query Filtering: Use the
get_transactions
endpoint with filters to narrow down transactions toMoveCall
with thepublish
function. - WebSocket Streaming: Stream all transactions and filter for
MoveCall
transactions related to publishing. - Explorer: Use the Sui Explorer for manual tracking, especially useful for visual inspection.
- Periodic Polling: Implement a polling mechanism to fetch transactions regularly for new publish events.
Each method can be adapted based on your use case—whether you're building an automated system or just need quick manual checks.
Do you know the answer?
Please log in and share it.
Sui is a Layer 1 protocol blockchain designed as the first internet-scale programmable blockchain platform.
- How to Maximize Profit Holding SUI: Sui Staking vs Liquid Staking615
- Why does BCS require exact field order for deserialization when Move structs have named fields?65
- Multiple Source Verification Errors" in Sui Move Module Publications - Automated Error Resolution55
- Sui Move Error - Unable to process transaction No valid gas coins found for the transaction419
- Sui Transaction Failing: Objects Reserved for Another Transaction410