# Stellar network

D'CENT mobile app's in-app browser injects `window.freighterApi` as a provider for the Stellar network. If your dapp is based on Stellar, you can interact with D'CENT wallet through the `window.freighterApi` provider, the same interface used by the Freighter wallet.

Unlike EVM networks (which expose a D'CENT-specific `window.ethereum`), D'CENT implements the **Freighter API** and the **SEP-43 (Standard Web Wallet API Interface)** standard for Stellar. This means dapps that are already integrated with Freighter, either directly or through Stellar Wallets Kit, work with D'CENT without code changes.

### Supported Networks <a href="#supported-networks" id="supported-networks"></a>

The following is the D'CENT in-app browser's supported Stellar network list which can use the `window.freighterApi` provider.

| Network          | Network Passphrase                               |
| ---------------- | ------------------------------------------------ |
| PUBLIC (Mainnet) | `Public Global Stellar Network ; September 2015` |
| TESTNET          | `Test SDF Network ; September 2015`              |

#### How to Switch the Network <a href="#how-to-switch-the-network" id="how-to-switch-the-network"></a>

By clicking the "network" icon on the right top corner of the "discovery" tab, you can switch the blockchain network for the dapp browser.

For more details, please see the D'CENT user guide.

* Switch Network User Guide : <https://userguide.dcentwallet.com/native-service/dapp-browser/switch-blockchain-network>

### If your dapp is already integrated with Freighter <a href="#if-your-dapp-is-already-integrated-with-freighter" id="if-your-dapp-is-already-integrated-with-freighter"></a>

D'CENT wallet's Stellar provider implements the Freighter API and the SEP-43 standard interface.

* Freighter API : <https://docs.freighter.app/>
* @stellar/freighter-api (npm) : <https://www.npmjs.com/package/@stellar/freighter-api>
* SEP-43 Standard Web Wallet API Interface : <https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0043.md>

Freighter exposes its API through the `window.freighterApi` object, and the `@stellar/freighter-api` package reads from that object automatically. D'CENT injects the same object, so if your dapp is already integrated with Freighter, it's very easy to integrate with D'CENT wallet.

For your reference, you can also find Freighter's developer guide in the link below.

* Freighter Developer Guide : <https://docs.freighter.app/>

#### If your dapp uses Stellar Wallets Kit <a href="#if-your-dapp-uses-stellar-wallets-kit" id="if-your-dapp-uses-stellar-wallets-kit"></a>

Most modern Stellar dapps connect through [Stellar Wallets Kit](https://stellarwalletskit.dev/). Because D'CENT exposes the Freighter API (`window.freighterApi` and the legacy `window.freighter`), the Kit's **Freighter module** detects D'CENT through its `isConnected()` probe and routes signing requests to it. No D'CENT-specific module is required: register the Freighter module in your Kit setup and D'CENT becomes selectable (shown as "Freighter").

```javascript
import { FREIGHTER_ID, FreighterModule } from '@creit.tech/stellar-wallets-kit';

// Register the Freighter module in your existing Stellar Wallets Kit configuration.
// NOTE: the Kit's constructor/init signature changed between major versions
//   v1.x : new StellarWalletsKit({ network: WalletNetwork.PUBLIC, selectedWalletId, modules })
//   v2.x : StellarWalletsKit.init({ network: Networks.PUBLIC, selectedWalletId, modules })  // static API; `Networks` replaces `WalletNetwork`
// Follow the Stellar Wallets Kit docs for your installed version.
const modules = [new FreighterModule()];
const selectedWalletId = FREIGHTER_ID;
```

When the user selects "Freighter" inside D'CENT's in-app browser, the Kit communicates with D'CENT through the injected Freighter API described below.

### How to detect in-app browser <a href="#how-to-detect-in-app-browser" id="how-to-detect-in-app-browser"></a>

In order to check if your dapp running on Stellar is supported by the dapp browser, you need to check whether `window.freighterApi` is defined.

```javascript
if (typeof window.freighterApi !== 'undefined') {
    console.log("It's in-app browser");
}
```

#### How to check D'CENT provider <a href="#how-to-check-dcent-provider" id="how-to-check-dcent-provider"></a>

Several Stellar dapp browsers expose the same `window.freighterApi` interface. You can check whether the dapp browser is D'CENT wallet's in-app browser with the following code.

```javascript
if (window.freighterApi.isDcentWallet === true) {
    console.log("It's D'CENT wallet's in-app browser")
}
```

D'CENT also exposes a dedicated provider handle, which you can use as an alternative detection point.

```javascript
if (typeof window.dcentStellarProvider !== 'undefined') {
    console.log("It's D'CENT wallet's in-app browser")
}
```

### Connect to Wallet <a href="#connect-to-wallet" id="connect-to-wallet"></a>

You can use the following code in order to connect to a D'CENT wallet account. `requestAccess()` prompts the user for approval and returns the selected account address.

```javascript
const { address, error } = await window.freighterApi.requestAccess();

if (error) {
  console.error(error);
} else {
  console.log('Connected address:', address);
}
```

You can also check the connection and permission state without prompting the user.

```javascript
const { isConnected } = await window.freighterApi.isConnected();
const { isAllowed } = await window.freighterApi.isAllowed();
```

#### Wallet Connection UI <a href="#wallet-connection-ui" id="wallet-connection-ui"></a>

If the connection to the wallet is requested, a connection approval popup appears.

### Get the current network <a href="#get-the-current-network" id="get-the-current-network"></a>

To get the current network and its passphrase, you can use the following code.

```javascript
const { network, networkPassphrase } = await window.freighterApi.getNetwork();
```

For full network details (passphrase, Horizon URL, and Soroban RPC URL), use the following code.

```javascript
const {
  network,
  networkPassphrase,
  networkUrl,      // Horizon URL
  sorobanRpcUrl,
} = await window.freighterApi.getNetworkDetails();
```

### Get the current account's address <a href="#get-the-current-accounts-address" id="get-the-current-accounts-address"></a>

To get the address of the current account, you can use the following code.

```javascript
const { address } = await window.freighterApi.getAddress();
```

### Sign Transaction <a href="#sign-transaction" id="sign-transaction"></a>

By using `signTransaction`, you can ask D'CENT wallet to sign a Stellar transaction. The transaction is passed as a base64-encoded XDR string together with the network passphrase and the signer address. D'CENT returns the **signed XDR**, and your dapp submits it to the network (Horizon or Soroban RPC).

```javascript
import {
  TransactionBuilder,
  Networks,
  Operation,
  Asset,
  Horizon,
} from '@stellar/stellar-sdk';

const server = new Horizon.Server('https://horizon.stellar.org');
const account = await server.loadAccount(address);

const tx = new TransactionBuilder(account, {
  fee: '100',
  networkPassphrase: Networks.PUBLIC,
})
  .addOperation(
    Operation.payment({
      destination: 'G...DESTINATION',
      asset: Asset.native(),
      amount: '1.5',
    }),
  )
  .setTimeout(180)
  .build();

// Ask D'CENT to sign the transaction.
const { signedTxXdr, signerAddress } = await window.freighterApi.signTransaction(
  tx.toXDR(),
  {
    networkPassphrase: Networks.PUBLIC,
    address, // signer address
  },
);

// Submit the signed transaction yourself.
const signedTx = TransactionBuilder.fromXDR(signedTxXdr, Networks.PUBLIC);
const result = await server.submitTransaction(signedTx);
console.log('Transaction hash:', result.hash);
```

#### Sign Soroban authorization entries and messages <a href="#sign-soroban-authorization-entries-and-messages" id="sign-soroban-authorization-entries-and-messages"></a>

For Soroban smart-contract dapps, D'CENT also implements authorization-entry signing and message signing.

```javascript
// Sign a Soroban authorization entry (base64 XDR of a HashIdPreimage).
const { signedAuthEntry, signerAddress } = await window.freighterApi.signAuthEntry(authEntryXdr, {
  address,
  networkPassphrase: Networks.PUBLIC,
});

// Sign an arbitrary message.
const { signedMessage, signerAddress } = await window.freighterApi.signMessage(message, {
  address,
  networkPassphrase: Networks.PUBLIC,
});
```

### Reference <a href="#reference" id="reference"></a>

* Freighter API documentation : <https://docs.freighter.app/>
* @stellar/freighter-api (npm) : <https://www.npmjs.com/package/@stellar/freighter-api>
* SEP-43 Standard Web Wallet API Interface : <https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0043.md>
* Stellar Wallets Kit : <https://stellarwalletskit.dev/>
* Stellar SDK (@stellar/stellar-sdk) : <https://www.npmjs.com/package/@stellar/stellar-sdk>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dev-docs.dcentwallet.com/in-app-browser/stellar-network.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
