API Reference

Once the script is connected, a window.OpenWeb3.WebApp object will become available with the following fields:

WebApp

FieldTypeDescription
initDataStringA string with raw data transferred to the Mini App, convenient for validating data.
WARNING: Validate data from this field before using it on the bot's server.
initDataUnsafeWebAppInitDataAn object with input data transferred to the Mini App.
WARNING: Data from this field should not be trusted. You should only use data from initData on the bot's server and only after it has been validated.
versionStringThe version of the Bot API available in the user's client app.
platformStringThe name of the platform of the user's client app.
colorSchemeThemeParamsAn object containing the current theme settings used in the client app.
isExpandedBooleanTrue, if the Mini App is expanded to the maximum available height. False, if the Mini App occupies part of the screen and can be expanded to the full height using the expand() method.
viewportHeightFloatThe current height of the visible area of the Mini App. Also available in CSS as the variable var(--tg-viewport-height).

The application can display just the top part of the Mini App, with its lower part remaining outside the screen area. From this position, the user can “pull” the Mini App to its maximum height, while the bot can do the same by calling the expand() method. As the position of the Mini App changes, the current height value of the visible area will be updated in real time.

Please note that the refresh rate of this value is not sufficient to smoothly follow the lower border of the window. It should not be used to pin interface elements to the bottom of the visible area. It's more appropriate to use the value of the viewportStableHeight field for this purpose.
viewportStableHeightFloatThe height of the visible area of the Mini App in its last stable state. Also available in CSS as a variable var(--dj-viewport-stable-height).

The application can display just the top part of the Mini App, with its lower part remaining outside the screen area. From this position, the user can “pull” the Mini App to its maximum height, while the bot can do the same by calling the expand() method. Unlike the value of viewportHeight, the value of viewportStableHeight does not change as the position of the Mini App changes with user gestures or during animations. The value of viewportStableHeight will be updated after all gestures and animations are completed and the Mini App reaches its final size.

Note the event viewportChanged with the passed parameter isStateStable=true, which will allow you to track when the stable state of the height of the visible area changes.
headerColorStringCurrent header color in the #RRGGBB format.
backgroundColorStringCurrent background color in the #RRGGBB format.
isClosingConfirmationEnabledBooleanTrue, if the confirmation dialog is enabled while the user is trying to close the Mini App. False, if the confirmation dialog is disabled.
BackButtonBackButtonAn object for controlling the back button which can be displayed in the header of the Mini App in the client app interface.
MainButtonMainButtonAn object for controlling the main button, which is displayed at the bottom of the Mini App in the client app interface.
HapticFeedbackHapticFeedbackAn object for controlling haptic feedback.
BiometricManagerBiometricManagerAn object for controlling biometrics on the device.
setHeaderColor(color)FunctionYou can pass OpenWeb3.WebApp.themeParams.bg_color or OpenWeb3.WebApp.themeParams.secondary_bg_color as a color or bg_color, secondary_bg_color keywords.
setBackgroundColor(color)FunctionA method that sets the app background color in the #RRGGBB format. You can also use keywords bg_color and secondary_bg_color.
enableClosingConfirmation()Function A method that enables a confirmation dialog while the user is trying to close the Mini App.
disableClosingConfirmation()Function A method that disables the confirmation dialog while the user is trying to close the Mini App.
onEvent(eventType, eventHandler)FunctionA method that sets the app event handler. Check the list of available events.
offEvent(eventType, eventHandler)FunctionA method that deletes a previously set event handler.
sendData(data)FunctionA method used to send data to the bot. When this method is called, a service message is sent to the bot containing the data data of the length up to 4096 bytes, and the Mini App is closed. See the field web_app_data in the class Message.

This method is only available for Mini Apps launched via a Keyboard button.
switchInlineQuery(query[, choose_chat_types])Function A method that inserts the bot's username and the specified inline query in the current chat's input field. Query may be empty, in which case only the bot's username will be inserted. If an optional choose_chat_types parameter was passed, the client prompts the user to choose a specific chat, then opens that chat and inserts the bot's username and the specified inline query in the input field. You can specify which types of chats the user will be able to choose from. It can be one or more of the following types: users, bots, groups, channels.
openLink(url[, options])FunctionA method that opens a link in an external browser. The Mini App will not be closed.
Bot API 6.4+ If the optional options parameter is passed with the field try_instant_view=true, the link will be opened in Instant View mode if possible.

Note that this method can be called only in response to user interaction with the Mini App interface (e.g. a click inside the Mini App or on the main button)
openWebAppLink(url)FunctionA method that opens a new web app link inside the your app. The Mini App will not be closed after this method is called.

The Mini App will be closed after this method is called.
showPopup(params[, callback])Function A method that shows a native popup described by the params argument of the type PopupParams. The Mini App will receive the event popupClosed when the popup is closed. If an optional callback parameter was passed, the callback function will be called and the field id of the pressed button will be passed as the first argument.
showAlert(message[, callback])FunctionA method that shows message in a simple alert with a 'Close' button. If an optional callback parameter was passed, the callback function will be called when the popup is closed.
showConfirm(message[, callback])FunctionA method that shows message in a simple confirmation window with 'OK' and 'Cancel' buttons. If an optional callback parameter was passed, the callback function will be called when the popup is closed and the first argument will be a boolean indicating whether the user pressed the 'OK' button.
showScanQrPopup(params[, callback])FunctionA method that shows a native popup for scanning a QR code described by the params argument of the type ScanQrPopupParams. The Mini App will receive the event qrTextReceived every time the scanner catches a code with text data. If an optional callback parameter was passed, the callback function will be called and the text from the QR code will be passed as the first argument. Returning true inside this callback function causes the popup to be closed. Starting from Bot API 7.7, the Mini App will receive the scanQrPopupClosed event if the user closes the native popup for scanning a QR code.
closeScanQrPopup()FunctionA method that closes the native popup for scanning a QR code opened with the showScanQrPopup method. Run it if you received valid data in the event qrTextReceived.
readTextFromClipboard([callback])FunctionA method that requests text from the clipboard. The Mini App will receive the event clipboardTextReceived. If an optional callback parameter was passed, the callback function will be called and the text from the clipboard will be passed as the first argument.

Note: this method can be called only for Mini Apps launched from the attachment menu and only in response to a user interaction with the Mini App interface (e.g. a click inside the Mini App or on the main button).
requestWriteAccess([callback])FunctionA method that shows a native popup requesting permission for the bot to send messages to the user. If an optional callback parameter was passed, the callback function will be called when the popup is closed and the first argument will be a boolean indicating whether the user granted this access.
requestContact([callback])FunctionA method that shows a native popup prompting the user for their phone number. If an optional callback parameter was passed, the callback function will be called when the popup is closed and the first argument will be a boolean indicating whether the user shared its phone number.
ready()FunctionA method that informs your app that the Mini App is ready to be displayed.
It is recommended to call this method as early as possible, as soon as all essential interface elements are loaded. Once this method is called, the loading placeholder is hidden and the Mini App is shown.
If the method is not called, the placeholder will be hidden only when the page is fully loaded.
expand()FunctionA method that expands the Mini App to the maximum available height. To find out if the Mini App is expanded to the maximum height, refer to the value of the OpenWeb3.WebApp.isExpanded parameter
isVerticalSwipesEnabledBooleanTrue, if vertical swipes to close or minimize the Mini App are enabled. False, if vertical swipes to close or minimize the Mini App are disabled. In any case, the user will still be able to minimize and close the Mini App by swiping the Mini App's header.
enableVerticalSwipes()FunctionA method that enables vertical swipes to close or minimize the Mini App. For user convenience, it is recommended to always enable swipes unless they conflict with the Mini App's own gestures.
disableVerticalSwipes()FunctionA method that disables vertical swipes to close or minimize the Mini App. This method is useful if your Mini App uses swipe gestures that may conflict with the gestures for minimizing and closing the app.
isActionBarVisibleBooleanisActionBarVisible is a boolean attribute that indicates whether the action bar is currently visible in the Mini App's user interface. If the value is true, it means the action bar is visible, and if the value is false, it means the action bar is hidden.
enableActionBar()FunctionenableActionBar() is a method that allows the Mini App to enable the action bar in its user interface. The action bar typically contains important controls and navigation elements for the Mini App. By calling this method, the Mini App ensures that the action bar is displayed to the user.
disableActionBar()FunctiondisableActionBar() is a method that allows the Mini App to disable the action bar in its user interface. By calling this method, the Mini App hides the action bar from the user, removing any associated controls and navigation elements.
isFullScreenEnabledBooleanisFullScreenEnabled is a boolean attribute that indicates whether the Mini App is currently in full-screen mode. If the value is true, it means the Mini App is displayed in full-screen mode, occupying the entire screen. If the value is false, it means the Mini App is not in full-screen mode and may have a different display area or size.
enableFullScreen()FunctionenableFullScreen() is a method that allows the Mini App to enter full-screen mode, expanding its display to occupy the entire screen. By calling this method, the Mini App provides a more immersive experience for the user, removing any surrounding elements or distractions from the screen.
disableFullScreen()FunctiondisableFullScreen() is a method that allows the Mini App to exit full-screen mode and return to its default display mode. By calling this method, the Mini App restores its original display area and may show surrounding elements or user interface components.

WebAppInitData

ParameterTypeDescription
auth_dateNumberThe date the initialization data was created. Is a number representing a Unix timestamp.
hashStringInitialization data signature.
start_paramStringOptional. The value of the startattach or startapp query parameter specified in the link. It is returned only for Mini Apps opened through the attachment menu.
userWebAppUserOptional. An object containing data about the current user.

WebAppUser

ParameterTypeDescription
idnumberA unique identifier for the user or bot or OpenWeb3 Id.
is_botBooleanOptional. True, if this user is a bot. Returns in the receiver field only.
first_nameStringFirst name of the user or bot.
last_nameStringOptional. Last name of the user or bot.
usernameStringOptional. Username of the user or bot.
language_codeStringOptional. IETF language tag of the user's language. Returns in user field only.
photo_urlStringOptional. URL of the user’s profile photo. The photo can be in .jpeg or .svg formats. Only returned for Mini Apps launched from the attachment menu.

BackButton

FieldTypeDescription
isVisibleBooleanShows whether the button is visible. Set to false by default.
onClick(callback)FunctionA method that sets the button press event handler. An alias for OpenWeb3.WebApp.onEvent('backButtonClicked', callback)
offClick(callback)FunctionA method that removes the button press event handler. An alias for OpenWeb3.WebApp.offEvent('backButtonClicked', callback)
show()FunctionA method to make the button active and visible.
hide()FunctionA method to hide the button.

MainButton

FieldTypeDescription
textStringCurrent button text. Set to CONTINUE by default.
colorStringCurrent button color. Set to themeParams.button_color by default.
textColorStringCurrent button text color. Set to themeParams.button_text_color by default.
isVisibleBooleanShows whether the button is visible. Set to false by default.
isActiveBooleanShows whether the button is active. Set to true by default.
isProgressVisibleBooleanReadonly. Shows whether the button is displaying a loading indicator.
setText(text)FunctionA method to set the button text.
onClick(callback)FunctionA method that sets the button press event handler. An alias for OpenWeb3.WebApp.onEvent('mainButtonClicked', callback)
offClick(callback)FunctionA method that removes the button press event handler. An alias for OpenWeb3.WebApp.offEvent('mainButtonClicked', callback)
show()FunctionA method to make the button visible.
Note that opening the Mini App from the attachment menu hides the main button until the user interacts with the Mini App interface.
hide()FunctionA method to hide the button.
hide()FunctionA method to enable the button.
disable()FunctionA method to disable the button.
showProgress(leaveActive)FunctionA method to show a loading indicator on the button.
It is recommended to display loading progress if the action tied to the button may take a long time. By default, the button is disabled while the action is in progress. If the parameter leaveActive=true is passed, the button remains enabled.
hideProgress()FunctionA method to hide the loading indicator.
setParams(params)FunctionA method to set the button parameters. The params parameter is an object containing one or several fields that need to be changed:
text - button text;
color - button color;
text_color - button text color;
is_active - enable the button;
is_visible - show the button.

BiometricManager

FieldTypeDescription
isInitedBooleanShows whether biometrics object is initialized.
isBiometricAvailableBooleanA Shows whether biometrics is available on the current device.
biometricTypeStringThe type of biometrics currently available on the device. Can be one of these values:

- finger, fingerprint-based biometrics,
- face, face-based biometrics,
- unknown, biometrics of an unknown type.
isAccessRequestedFunctionShows whether permission to use biometrics has been requested.
isAccessGrantedFunction Shows whether permission to use biometrics has been granted.
isBiometricTokenSavedBooleanShows whether the token is saved in secure storage on the device.
deviceIdStringA unique device identifier that can be used to match the token to the device.
init([callback])FunctionA method that initializes the BiometricManager object. It should be called before the object's first use. If an optional callback parameter was passed, the callback function will be called when the object is initialized.
requestAccess(params[, callback])FunctionA method that requests permission to use biometrics according to the params argument of type BiometricRequestAccessParams. If an optional callback parameter was passed, the callback function will be called and the first argument will be a boolean indicating whether the user granted access.
authenticate(params[, callback])FunctionA method that authenticates the user using biometrics according to the params argument of type BiometricAuthenticateParams. If an optional callback parameter was passed, the callback function will be called and the first argument will be a boolean indicating whether the user authenticated successfully. If so, the second argument will be a biometric token.
updateBiometricToken(token, [callback])FunctionA method that updates the biometric token in secure storage on the device. To remove the token, pass an empty string. If an optional callback parameter was passed, the callback function will be called and the first argument will be a boolean indicating whether the token was updated.
openSettings()FunctionA method that opens the biometric access settings for bots. Useful when you need to request biometrics access to users who haven't granted it yet.

Note that this method can be called only in response to user interaction with the Mini App interface (e.g. a click inside the Mini App or on the main button)