[TEP-105] Standardizing the Web3 Provider Interface in TON: A JavaScript API Proposal

,

Abstract

This document proposes a standardized JavaScript API for Web3 providers on the TON blockchain, aiming to ensure consistency and interoperability across clients and decentralized applications (DApps). By formalizing the Web3 Provider API, this TEP (TON Enhancement Proposal) seeks to establish a common convention for wallet software to expose their API via a JavaScript object in web pages, enhancing the developer experience and facilitating user interaction with DApps.

Proposal Information

  • TEP (TON Enhancement Proposal): 0
  • Title: Standardizing the Web3 Provider Interface in TON: A JavaScript API Proposal
  • Status: Draft
  • Type: Core
  • Authors: XTON Wallet Team
  • Creation Date: 19.12.2022
  • Replaces: TEP-0
  • Replaced by: None

Motivation

The main goal of this proposal is to establish a uniform Web3 provider interface, preventing the monopolization of wallet services and enabling DApps to integrate with multiple wallet solutions seamlessly. Inspired by successful implementations in other blockchains, such as Ethereum’s MetaMask, this proposal introduces window.ton as the uniform interface for Web3 providers on the TON blockchain.

Specification

The specification outlines the structure of the proposed API, emphasizing minimalism, event-driven architecture, and transport agnosticism. It also introduces backward compatibility and extensibility through versioning, with windows.ton.isTEPs105 indicating full API compliance.

Comparison Table: Current vs. Proposed API Features

Feature Current Implementation Proposed Standardization
Interface Exposure Inconsistent across wallets Unified as window.ton
Versioning Not standardized Standardized with isTEPs property
Request Handling Diverse, wallet-specific Standardized Provider.request method
Event Handling Varies widely Standardized events: on, off, message, endpointChanged, accountChanged, unlockStateChanged
RPC Methods Wallet-specific implementations Standardized naming and handling
Subscriptions Inconsistently supported Standardized with ton_subscription event
Error Handling Diverse, not standardized Standardized ProviderRpcError with defined codes

Security Considerations

The proposal emphasizes the Provider’s role as a bridge between TON Clients and DApps, not handling private key management but focusing on processing RPC messages and emitting events. It stresses the importance of treating the Provider object as potentially controlled by adversaries, highlighting the need for protective measures in the Wallet and Client against malicious actions.

Drawbacks and Rationale

While existing wallets have their implementations of the Web3 interface, adopting this standardized API would require them to support both the new standard and their existing interfaces. The proposal justifies its approach by pointing to the success of similar standards in other blockchain ecosystems, arguing for the benefits of a unified and interoperable interface.

Unresolved Questions and Future Possibilities

The document raises questions about the willingness of existing wallet solutions to adopt this standardized interface and suggests potential future extensions to include SDK method usage, enhancing the DApp development experience further.

Conclusion

This TEP proposes a significant step toward standardizing the Web3 provider interface within the TON blockchain ecosystem. By adopting a uniform API, the proposal aims to simplify DApp development, enhance user experience, and foster an environment of interoperability and innovation among wallet providers and DApps.

Appendix and Additional Resources

The proposal includes appendices detailing the API’s consumer-facing documentation, examples of usage, and a comprehensive list of supported functions and events. These resources are designed to assist developers in integrating the standardized Web3 provider into their applications, ensuring a smooth transition to a more unified and efficient ecosystem.