ton_connect library
A pure Dart implementation of the TON Connect 2 protocol.
Classes
- Account
- An account exposed by the wallet.
- AppRequest
- A request from the dApp to the wallet.
- BridgeGateway
- Maintains a subscription to one bridge and posts messages to peers.
- BridgeMessage
- The envelope the bridge writes to a recipient's event stream.
- BridgeProvider
- Drives one TON Connect session over the HTTP bridge.
- BridgeSession
- Everything needed to resume a bridge session after a restart.
- ConnectEvent
- The wallet's reply to a ConnectRequest.
- ConnectEventError
- The connection failed or was declined.
- ConnectEventSuccess
- The user approved the connection.
- ConnectItem
- A data item the dApp asks the wallet to share during connect.
- ConnectItemReply
- A wallet reply to one requested connect item.
- ConnectRequest
- The first message of a session: what the dApp is, and what it wants.
- DeviceInfo
- Metadata describing the wallet application on the other side of the session.
- DisconnectEvent
- The wallet ended the session from its side.
- DisconnectRequest
- Tells the wallet the dApp has ended the session.
- EmbeddedRequest
- Encodes a request to ride along inside the connect URL.
- EmbeddedRequestFeature
- The wallet can process an embedded request carried in the connect URL.
- InjectedBridge
- The wallet object a wallet injects into the page.
- InjectedProvider
- Drives a session with a wallet that injected itself into the page.
- InMemoryStorage
- A TonConnectStorage that keeps everything in memory.
- JettonTransferItem
- A jetton transfer — USDT and every other TON token.
- JsWalletBridge
- The wallet injects a bridge object into the page.
- NftTransferItem
- An NFT transfer.
- ReturnStrategy
- Where the wallet sends the user after they approve or reject.
- SendTransactionFeature
-
The wallet can process
sendTransaction. - SendTransactionRequest
- Asks the wallet to sign and broadcast outgoing messages.
- SessionCrypto
- The X25519 keypair backing one TON Connect session.
- SignDataFeature
-
The wallet can process
signData. - SignMessageFeature
-
The wallet can process
signMessage. - SignMessageRequest
- Asks the wallet to sign messages without broadcasting them.
- SseEvent
- One dispatched server-sent event.
- SseTransport
- Opens server-sent event streams for the bridge.
- SseWalletBridge
- The wallet is reachable over the encrypted HTTP bridge.
- TonAddressItem
- Requests the account address, public key and state init.
- TonAddressItemReply
-
Reply to a
ton_addritem. - TonConnect
- The entry point for talking to a TON wallet.
- TonConnectSession
- The operations the facade needs from a live session, whichever transport carries it.
- TonConnectStorage
- Key-value storage for session state that must outlive the process.
- TonProof
- A signature proving the user controls the connected account.
- TonProofItem
- Requests a signature proving the user controls the connected account.
- TonProofItemReply
-
Reply to a
ton_proofitem, successful or failed. - TonTransferItem
- A plain TON transfer.
- TransactionItem
- A structured transfer the wallet composes into a message itself.
- TransactionMessage
- One raw outgoing message in a transaction.
- TransactionPayload
-
The payload of a
sendTransactionorsignMessagerequest. - UnknownFeature
- A feature this SDK revision does not model, preserved verbatim.
- UnknownItemReply
- A reply to an item this SDK revision does not model.
- WalletApp
- One entry from the public wallets registry.
- WalletBridge
- How a wallet can be reached.
- WalletConnection
- A live connection to a wallet.
- WalletEvent
- An event the wallet raises on its own.
- WalletFeature
-
A capability advertised by the wallet in
DeviceInfo.features. - WalletResponse
- The wallet's answer to one AppRequest.
- WalletResponseError
- The wallet refused or failed the request.
- WalletResponseSuccess
- The wallet completed the request.
- WalletsListManager
- Fetches and caches the public wallets registry.
Enums
- DevicePlatform
- Platform the connected wallet application runs on.
- SignDataType
-
Data type a wallet accepts in
signData. - TransactionItemType
-
Structured item type a wallet accepts in
sendTransaction/signMessage. - WalletPlatform
- A platform a wallet is available on.
Extension Types
- NetworkId
-
A TON network identifier — the stringified network
global_id.
Constants
- bridgeSessionStorageKey → const String
- Storage key holding the serialised BridgeSession.
- defaultWalletsListUrl → const String
- The canonical wallets registry.
- protocolVersion → const int
- The TON Connect protocol version this SDK speaks.
- unifiedDeepLinkBase → const String
- The unified deep link every wallet must accept.
- walletsListCacheKey → const String
- Storage key holding the last registry successfully fetched.
Properties
- hasInjectedWallet → bool
-
Whether any wallet injected itself into this page.
no setter
Functions
-
buildConnectLink(
{required String base, required String clientId, required ConnectRequest request, ReturnStrategy? returnStrategy, String? traceId, String? embeddedRequest}) → String - Builds the link that carries a ConnectRequest to a wallet.
-
buildWalletReturnLink(
{required String base, required String clientId, ReturnStrategy? returnStrategy = ReturnStrategy.back}) → String - Builds the link that brings an already-connected wallet to the foreground.
-
createSseTransport(
) → SseTransport - Creates the SseTransport appropriate for the current platform.
-
injectedWalletKeys(
) → List< String> -
The
windowkeys of wallets that injected themselves into this page. -
openInjected(
String key) → InjectedBridge? -
Opens the binding a wallet injected under
key, ornullwhen there is none.
Exceptions / Errors
- BadRequestError
- Code 1 — the request payload was malformed or violated method constraints.
- FeatureNotSupportedError
- The connected wallet does not advertise a feature the call requires.
- ManifestContentError
- Code 3 — the manifest was fetched but its contents are invalid.
- ManifestNotFoundError
- Code 2 — the wallet could not fetch the dApp manifest.
- MethodNotSupportedError
- Code 400 — the wallet does not implement the requested method.
- TonConnectBridgeError
- The bridge transport failed: HTTP error, dropped stream, or a malformed server-sent event.
- TonConnectError
- Base type for every error surfaced by this package.
- TonConnectParseError
- A wallet response or bridge envelope did not match the expected shape.
- TonConnectProtocolError
- An error returned by the wallet, carrying a protocol error code.
- TonConnectSessionError
- The session keypair or an encrypted bridge payload is unusable.
- UnknownAppError
- Code 100 — the wallet does not know this session or app.
- UnknownProtocolError
- Code 0, or any code this SDK revision does not recognise.
- UserDeclinedError
- Code 300 — the user explicitly declined the action.
- WalletAlreadyConnectedError
- A connect was attempted while a wallet is already connected.
- WalletNotConnectedError
- The operation requires a connected wallet, but none is connected.
- WalletsListError
- The wallets registry could not be fetched or parsed.