# Advanced

## Connect Wallet - Native

The code samples below trigger a wallet connection silently. No UI displays to the user. Your application is responsible for rendering the progress dialog, and for handling errors and allowing the user to cancel the app connect operation.

{% tabs %}
{% tab title="Unity" %}

```csharp
// Start connect flow
OVSdk.Sdk.AppConnectManager.ConnectWallet("in-game-user-id");

// Cancel currently active connect flow
OVSdk.Sdk.AppConnectManager.CancelConnect();
```

{% endtab %}

{% tab title="Android" %}

```java
// Start connect flow
VesselSdk.getInstance( activity )
         .getAppConnectManager()
         .connectWallet("in-game-user-id");
         
// Cancel currently active connect flow
VesselSdk.getInstance( activity )
         .getAppConnectManager()
         .cancelConnect();Load Balance Deeplink
```

{% endtab %}

{% tab title="iOS" %}

```objectivec
// Start connect flow
[[[OVLSdk sharedInstance] appConnectManager] 
    connectWalletWithUserId: @"in-game-user-id"];
         
// Cancel currently active connect flow
[[[OVLSdk sharedInstance] appConnectManager] cancelConnect];
```

{% endtab %}
{% endtabs %}

## Load Balance Deeplink

Load Balance allows Developer's to deeplink users directly into Vessel and prompt a coin purchase. Developers will use this feature under the circumstance they want a user to purchase an NFT but they do not have the sufficient amount of coins to do so:

{% tabs %}
{% tab title="Unity" %}

```csharp
// Deeplink to balance page
OVSdk.Sdk.WalletPresenter.LoadBalanceInWalletApplication(<wallet address>);

// Deeplink to balance page and prompt a specific purchase amount (i.e. - 70 coins)
OVSdk.Sdk.WalletPresenter.LoadBalanceInWalletApplication(<wallet address>, <coinamount>);
```

{% endtab %}

{% tab title="Android" %}

```java
// Deeplink to balance page
VesselSdk.getInstance( this ).getWalletPresenter().loadBalanceInWalletApplication( <wallet address>, <activity>);

// Deeplink to balance page and prompt a specific purchase amount (i.e. - 70 coins)
VesselSdk.getInstance( this ).getWalletPresenter().loadBalanceInWalletApplication( <wallet address>, <coinamount>, <activity>);
```

{% endtab %}

{% tab title="iOS" %}

```objectivec
// Deeplink to balance page
[OVLSdk.sharedInstance.presentationController loadBalanceInWalletApplication:<wallet address>];

// Deeplink to balance page and prompt a specific purchase amount (i.e. - 70 coins)
[OVLSdk.sharedInstance.presentationController loadBalanceInWalletApplication:<wallet address> byAmount:<coinamount>];
```

{% endtab %}
{% endtabs %}

## Verify Wallet Address in Vessel Application

Verify wallet address method lets you verify if the wallet address of the user is equal to the one, that he logged with, in the Vessel application. Note, that this method will redirect the user directly to the Vessel application after calling it, or advising him to install Vessel Wallet instead.

{% tabs %}
{% tab title="Unity" %}

```csharp
OVSdk.Sdk.WalletPresenter.VerifyWalletAddressInWalletApplication("wallet address");
```

{% endtab %}

{% tab title="Android" %}

```java
final VesselSdk sdk = VesselSdk.getInstance(currentActivity);

sdk.getWalletPresenter().verifyWalletAddressInWalletApplication("wallet address", currentActivity);
```

{% endtab %}

{% tab title="iOS" %}

```objectivec
[OVLSdk.sharedInstance.presentationController verifyWalletAddressInWalletApplication:@"wallet address"];
```

{% endtab %}
{% endtabs %}

## Disconnect a Wallet

Utilizing the following method disconnects a User's concurrently connected wallet and wipes the Vessel SDK state:

{% tabs %}
{% tab title="Unity" %}

```csharp
OVSdk.Sdk.AppConnectManager.DisconnectCurrentSession();
```

{% endtab %}

{% tab title="Android" %}

```java
VesselSdk.getInstance( activity )
         .getAppConnectManager()
         .disconnectCurrentSession()
```

{% endtab %}

{% tab title="iOS" %}

```objectivec
[[[OVLSdk sharedInstance] appConnectManager] 
  disconnectCurrentSessionWithResultHandler: ^{
    . . .
}];
```

{% endtab %}
{% endtabs %}

## Setup custom Load Balance logic

After pressing Load Balance button into your Profile page of your Vessel account in custom tab, Vessel SDK checks if custom presenter was used and overrided method could include your own screen to show available IAP products:

{% tabs %}
{% tab title="Unity" %}

```csharp
OVSdk.CustomPresenter.LoadBalancePresenter = ShowLoadBalance;

private void ShowLoadBalance()
{
    // ...
}
```

{% endtab %}

{% tab title="Android" %}

```java
final VesselSdk sdk = VesselSdk.getInstance( currentActivity );
sdk.getWalletPresenter().setCustomPresenter( customPresenter );

// Custom Presenter definition
@Override
public boolean showLoadBalance()
{
    // ...
    return true;
}
```

{% endtab %}

{% tab title="iOS" %}

```objectivec
OVLSdk.sharedInstance.presentationController.customPresenter = customPresenter;

// Custom Presenter definition
- (void)presentLoadBalance
{
    // ...
}
```

{% endtab %}
{% endtabs %}

## Set callback methods for handling IAP transactions

In order to follow the state of purchase, please use the next interface methods:

{% tabs %}
{% tab title="Unity" %}

```csharp
OVSdk.Sdk.IapManager.PurchaseProduct();

OVSdk.IapManagerCallbacks.OnPurchaseSuccess += PurchaseSuccess;
OVSdk.IapManagerCallbacks.OnPurchaseCancel += PurchaseCancelled; 
OVSdk.IapManagerCallbacks.OnPurchaseFailure += PurchaseFailed; 

public void PurchaseSuccess(OVSdk.SuccessfulPurchase successfulPurchase)
{
    // ...
}
public void PurchaseCancelled(OVSdk.CancelledPurchase cancelledPurchase)
{
    // ...
}
public void PurchaseFailed(OVSdk.FailedPurchase failedPurchase)
{
    // ...
}
```

{% endtab %}

{% tab title="Android" %}

```java
final VesselSdk sdk = VesselSdk.getInstance(currentActivity);
sdk.getIapManager().purchaseProduct( productId, currentActivity ).whenComplete( (verificationObject, th) -> {
        if ( th != null )
        {
            final boolean isCancelled = Optional
                    .ofNullable( th.getCause() )
                    .filter( IapException.class::isInstance )
                    .map( IapException.class::cast )
                    .map( e -> e.isCanceled() )
                    .orElse( false );

        if ( isCancelled )
            {
            // handle cancel
            }
        else
            {
            // handle failure
            }
}
        else
            {
                // handle success
            }
        });
```

{% endtab %}

{% tab title="iOS" %}

```objectivec
[OVLSdk.sharedInstance.iapManager setDelegate: self
                                    delegateQueue: dispatch_get_main_queue()];

[OVLSdk.sharedInstance.iapManager purchaseProductWithIdentifier:@"product id"];

// Delegate definition
- (void)iapManager:(OVIapManagerDelegateForwarder *)iapManager didCancelPurchaseWithProductIdentifier:(NSString *)productId 
{
    // ...
}

- (void)iapManager:(OVIapManagerDelegateForwarder *)iapManager didFailPurchaseWithProductIdentifier:(NSString *)productId error:(NSError *)error 
{
    // ...
}

- (void)iapManager:(OVIapManagerDelegateForwarder *)iapManager didCompletePurchaseWithProductIdentifier:(NSString *)productId receipt:(NSData *)receipt 
{
    // ...
}
```

{% endtab %}
{% endtabs %}


---

# 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://docs.openvessel.io/integration/EZzgG67O9oXGl9CReheF/sdk/advanced.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.
