Skip to main content

Installing PnP Unity SDK

Download the Unity Package

Download .unitypackage from our latest release and import the package file into your existing Unity3D project.

warning

You may encounter errors when importing this package into your existing project.

The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?)

To fix this problem you need to add the following line into the dependencies object which is inside the Packages/manifest.json file.

/Packages/manifest.json
"com.unity.nuget.newtonsoft-json": "3.2.1"
tip

We recommend you use the Nethereum Library for making the blockchain calls. You can check our documentation on how to integrate Nethereum it with Web3Auth here.

Configuration

Configure a Plug n Play project

  • Go to Developer Dashboard, create or select an Web3Auth project:

  • Add {{SCHEMA}}://{YOUR_APP_PACKAGE_NAME}/auth to Whitelist URLs.

  • Copy the Client ID for usage later.

Unity SDK works on Unity deep linking features to redirect the callback from Web3Auth. Before building the application for Android/IOS you need to register the redirect_uri, which can be easily done using the tool provided inside the SDK. To achieve that, you need to follow the steps mentioned below.

  • Open the "Deep Link Generator" tool provided by Web3Auth Unity SDK from Window > Web3Auth > Deep Link Generator

    Deep Link Generator
  • Enter the redirect_url {{SCHEMA}}://{YOUR_APP_PACKAGE_NAME}/auth and click generate.

tip

We're using torusapp://com.torus.Web3AuthUnity/auth as the redirect_url in our example just to give you a reference on how your app's redirect_url should look like.

Add Web3auth Configuration Script to the scene

  • Inside Project > Assets > Plugins > Web3AuthSDK there is a file called Web3auth that must be dragged to the component in the scene. In our examples we are using a canvas. So you can now configure you clientId, rediretUrl and Network from the UI.

    Config Web3Auth
    note

    This is an optional step, you can directly code these options on the code level in C# as well.

Android Configuration

  • Create an Android manifest in Unity by navigating to Edit > Project Settings > Player > Publishing Settings and clik over the "Custom Main Manifest" checkbox.

    Unity Add manifest

This is our AndroidManifest.xml file for our examples:

<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.unity3d.player"
xmlns:tools="http://schemas.android.com/tools">
<application>
<activity android:name="com.unity3d.player.UnityPlayerActivity"
android:theme="@style/UnityThemeSelector">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="torusapp" android:host="com.torus.Web3AuthUnity"
android:pathPrefix="/auth"
android:pathPattern="/*" />

</intent-filter>
<meta-data android:name="unityplayer.UnityActivity" android:value="true" />
</activity>
</application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<queries>
<intent>
<action android:name=
"android.support.customtabs.action.CustomTabsService" />
</intent>
</queries>
</manifest>

iOS Configuration

Once you build the unity project for iOS. You would need to open with the xCode and you would see and error informing that you have to choose a user certificate to sign the app. When you click on the error you will have to choose it with the configuration that you see in the image.

iOS Unity Team selection

After running the app, when testing on your iPhone/iPad, you need to approve the signer certificate on your device to run the apps. For this purpose on your device, go to General > VPN & Device Manager > Developer App.

iOS Unity Approve certificate