oleganza
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # TonApi Events ## Events and actions Events describe changes to the account balances in TON. Each event consists of one or more actions. Common transfers of coins and tokens are single-action events, while a trade on DEX produces a multi-action event. Each event provides information from the perspective of all involved accounts. For example, an [NftItemTransfer](#NftItemTransfer) event will be returned for the sender’s account, recipient’s account and for the token address. Events are offered in two flavors: * Type [Event](#Event) contains complete set of all the actions and fees for all parties involved. * Type [AccountEvent](#AccountEvent) contains a subset of actions relevant to a given account. Instead of a list of fees, it contains a single Fee object describing fees paid by the account. ## Events vs transactions TON blockchain consists of _contracts_ that send _messages_ to each other and update their own states via _transactions_. These are low-level building blocks for the wallets, tokens and decentralized apps. _Events_ and _actions_ are higher level abstractions that combine together multiple messages and transactions in a single entity that is easier to understand. For example, a single action `NftSend` consists of three transactions: (1) authentication on the sender’s wallet, (2) ownership update on the NFT contract, (3) notification sent to the new owner. Transactions and messages form a tree, while events are flat lists of actions. ## Understanding fees TON network has a complex system of fees. Sometimes both the sender and the recipient are paying fees for storage (_rent_) and processing costs (_gas_). When an additional contract is deployed, wallets typically send extra coins to cover the costs and initial balance of a new contract as _deposit_, while receiving unused back as _refund_. One account may produce multiple actions while paying common fees for its storage and gas. To avoid any confusion, on API response for an event there can be return Array of [Fee](#Fee) objects, each for every account involved. The fees are broken down in the following slots: * **total**: total amount of fees paid by the account during the event. Calculated as `gas`+`rent`+`deposit`-`refund`. * **gas**: total amount of coins spent for the processing of the messages by the account over all transactions within the event. * **rent**: total amount of coins paid for the storage rent by the account. * **deposit**: total amount of coins transferred by the wallet to cover the costs of the entire transaction chain. Some of these are left as balances of the newly created contracts. * **refund**: excess coins from the `deposit` that were returned to the sender after the operation is completed. Note: sometimes `refund` may exceed `deposit` and the `total` fees could become negative. This may happen e.g. when a subscription contract is destroyed and its balance is returned to the merchant. ## Presenting events To display the events correctly it is necessary to filter out actions that are not related to the account. This is done automatically by the API when you request [AccountEvents](#AccountEvent) instead of plain [Events](#Event). The user’s wallet should check whether the transfer is incoming or outgoing using the sender/recipient addresses. ## Failed actions Actions may fail and the appropriate messages may or may not bounce. Failure is indicated by the `status` field in each action. Bouncing is not indicated explicitly, but is reflected in `refund` field in the fees: * If the message has failed and bounced, then the action is considered as not happened; the TONs sent are marked within the `deposit` in the `Fee` object and returned TONs are specified in the `refund` field. * If the message has failed, but not bounced, then action is considered as not happened; the TONs sent are marked within the `deposit` in the `Fee` object. * If the message is sent as non-bounceable to the uninitialized contract, then the action is successful. ## Versioning Each version of API guarantees a fixed set of events. E.g. if v1 does not recognize usage of a DEX, it will return a simple `JettonTransfer` with a recipient address being the DEX contract. When v2 adds `JettonPlaceOnSale` action, old clients will still render plain transfers. From the API perspective all the newer actions are reformatted in terms of older actions on the fly for compatibility. ## Definitions ### Event Complete description of the event for all accounts involved. This event can be returned for any TON contract address: wallet account, NFT item, subscription contract, sale contract etc. ```json { "event_id": "<event-id>", "timestamp": 15612039230, // timestamp of the initial transaction "fees": [Fee], // "actions": [ Action<TonTransfer>, Action<TonDeploy>, Action<NftCollectionCreate>, Action<NftCollectionTransfer>, Action<NftItemCreate>, Action<NftItemTransfer>, Action<NftSalePlace>, Action<NftSaleFulfill>, Action<JettonMint>, Action<JettonTransfer>, Action<JettonBurn>, Action<SubscriptionCreate>, Action<SubscriptionCancel>, Action<SubscriptionPayment>, ] } ``` ### AccountEvent Filtered-down description of the event for a given account. Contains a subset of actions that are relevant to the given account. This event can only be returned for wallet contracts. If you want to receive events for a given token or a sale contract, request [Events](#event) instead. ```json { "event_id": "<event-id>", "timestamp": 15612039230, // timestamp of the initial transaction "account": Account, "fee": Fee, "actions": [ Action<TonTransfer>, Action<TonDeploy>, Action<NftCollectionCreate>, Action<NftCollectionTransfer>, Action<NftItemCreate>, Action<NftItemTransfer>, Action<NftSalePlace>, Action<NftSaleFulfill>, Action<JettonMint>, Action<JettonTransfer>, Action<JettonBurn>, Action<SubscriptionCreate>, Action<SubscriptionCancel>, Action<SubscriptionPayment>, ] } ``` ### Fee ```json { "account": Address, // account that paid the fees "total": "100", // = gas+rent+deposit-refund "gas": "80", // nanocoins cost of gas "rent": "10", // nanocoins cost of rent "deposit": "110", // nanocoins sent with the message from the account "refund": "100", // nanocoins returned to the account as a response msg or a bounced msg } ``` ### Action ```json { "type": "<action-type>", "status": ActionStatus, "<action-type>": TonTransfer | TonDeploy | NftCollectionCreate... } ``` ### ActionStatus Action could be pending, completed or failed. ```json ActionStatus = "pending" | "ok" | "failed" ``` Pending status is for actions that map to queued outgoing messages that are not yet processed by the destination contract and shardchain. Pending status may also belong to all the actions when the event is in the mempool. Failed action maps on a failed transaction. Such transaction may or may not bounce the message: the resulting difference in coins is reflected within the [Fee](#Fee) structure. ### TonTransfer ```json { "amount": "100000000", // nanocoins "recipient": Account, // address of the recipient "sender": Account, // address of the sender "payload": "<hex-encoded payload>", "comment": "Hello, world", // optional } ``` ### TonDeploy ```json { "amount": "100000000", // nanocoins "recipient": Account, // address of the recipient "sender": Account, // address of the sender "state_init": "<hex-encoded stateinit>", // recipient’s StateInit "payload": "<hex-encoded payload>", "comment": "Hello, world", // optional } ``` ### NftCollectionCreate TBD. ### NftCollectionTransfer TBD. ### NftItemCreate TBD. ### NftItemTransfer ```json { "nft": NFTItem, "sender": Account, // address of the sender "recipient": Account, // address of the recipient "payload": "<hex-encoded payload>", "comment": "Hello, world" // utf8 string from payload } ``` ### NftSalePlace ```json { "owner": Account, // owner of the token who places it on sale "nft_item": NFTItem, "nft_collection": NFTCollection "sale_id": Address, // contract of the sale "price": { "currency": "TON", "amount": "12345", // nanocoins }, }, ``` ### NftSaleFulfill When the sale is fulfilled, the payment is reflected in the `TonTransfer` action towards the seller’s account. ```json { "nft_item": NFTItem, "nft_collection": NFTCollection "sale_id": Address, // contract of the sale "recipient": Account, // who received the token "owner": Account, }, ``` ### JettonMint TBD. ### JettonTransfer ```json { "jetton": Jetton, "amount": "1000000", // base units for this jetton "sender": Account, // address of the sender "recipient": Account, // address of the recipient "payload": "<hex-encoded payload>", "comment": "Hello, world" // utf8 string from payload } ``` ### JettonBurn TBD. ### SubscriptionCreate When the subscription is created, full amount is deposited to the subscription contract. The base amount is left on the contract and the remaining coins are transferred out to the recipient. Hence, the difference is paid by the recipient and recorded as `FeePayment.deposit`. ```json { "recipient": Account, "sender": Account, "contract_id": Address, "subscription": Subscription, "amount": "1000000000", // nanocoins "interval": "2629800", // seconds }, ``` ### SubscriptionCancel Reminder of coins on the subscription contract are recorded as `FeePayment.refund` for the recipient. Coins attached to the message by the user who cancels subscription are recorded as `FeePayment.deposit` on their end. ```json { "recipient": Account, "sender": Account, "contract_id": Address, "subscription": Subscription, }, ``` ### SubscriptionPayment ```json { "recipient": Account, "sender": Account, "contract_id": Address, "amount": "1000000000", "subscription": Subscription, }, ``` ## Entities ### Address Address represents TON contract location: workchain + hash. ```json Address = "<wc>:<hex-encoded hash>" // e.g. 0:afe8f8ade781324... ``` ### Account ```json { "address": Address, "name": "Ton foundation" // optional "icon": "https://ton.org/logo.png", // optional "isScam": false, // optional } ``` ### NFTItem ```json { "id": Address, "collection_id": Address, // optional "name": "Token name", ... } ``` ### NFTCollection ```json { "id": Address, "name": "Collection name", ... } ``` ### Jetton ```json { "id": Address, "name": "Token name", "symbol": "TKN", "icon": "https://example.com/tkn.png", "divisibility": 9, ... } ``` ### Subscription ```json { "id": Address, "amount": "10000000", // nanocoins "interval": 23564800, // seconds "name": "Product name", // optional } ```

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully