Using Freighter in the browser
We now have an extension installed on our machine and a library to interact with it. This library will provide you methods to send and receive data from a user's extension in your website or application.
Importing
First import the library in the <head>
tag of your page.
Install the packaged library via script
tag using cdnjs. For example, use the following code to install the latest freighter api version:
<head><script src='https://cdnjs.cloudflare.com/ajax/libs/stellar-freighter-api/3.0.0/index.min.js' /></head>
NOTE: You can swap in another desired version number but you must use at least version 1.1.2
or above.
This will expose a global variable called window.freighterApi
that will contain our library.
The call signatures will be exactly the same as the node version, but you will call the methods directly from window.freighterApi
:
For example:
if (await window.freighterApi.isConnected()) {
alert("User has Freighter!");
}