Unity Setup
Learn how to create a Unity application and initialize it with the Okto SDK, including setting up authentication and executing your first token transfer.
Quick Start Template Available!
Skip the manual setup and get started in minutes with our template repository. It includes pre-configured Okto SDK integration, authentication setup, and example components and operations.
Before you begin, ensure you've completed these steps in the Okto Developer Dashboard:
- Created your dashboard account
- Obtained Okto credits from Okto Faucet for testing
- Generated your API keys
- Enabled the specific chains and tokens you plan to use in your application
- Optional: Configured sponsorship for seamless gas abstracted transactions.
Need assistance? Use our troubleshooting form and we'll help you get started.
Prerequisites
Before getting started, ensure you have the following:
- Google SignIn Package: Download Package
- Okto API Keys: You need your
clientPrivateKey
andclientSwa
. Obtain these from the Okto Developer Dashboard. - Google OAuth Credentials: Create OAuth 2.0 credentials in the Google Cloud Console to get your
webClientId
.
- Go to Google Cloud Console.
- Create a new project or select an existing one
- Create OAuth 2.0 credentials for your project.
- Save your Client ID.
- Add authorized redirect URIs if necessary
Need detailed instructions? Check our Google Console Setup Guide.
1. Create a new Unity project.
If you already have a Unity project, you can skip this step and proceed directly to Step 2 to start integrating Okto.
To create a new Unity project, just go to Unity Hub and choose version 2022.3.11f1
or higher.
Unity projects are generally not backward compatible. For the best experience, use the latest LTS (Long Term Support) version when starting your project.
2. Install Dependencies
Import the required packages:
Google Sign-In is a plugin that allows users to authenticate with their Google accounts in Unity applications.
Repository: https://github.com/googlesamples/google-signin-unity/releases
3. Configure Environment Variables
Set up your authentication credentials for Google and Okto services:
Replace the placeholders with your actual credentials.
- Never commit your
webClientId
parameter to version control. Add it to your.gitignore
.
4. Initialize the Okto Client
Update your OktoClient.cs
to initialize the Okto SDK:
This initializes the core Okto functionality in your Unity application, establishing a connection to the Okto backend services.
5. Set Up Google Authentication
Implement Google Sign-In functionality:
This configures the Google Sign-In provider with your credentials.
6. Implement User Authentication
Currently, you can onboard users and support on-chain interaction via the Okto Embedded wallet. To do this you must first authenticate your user via social login. We currently support Google OAuth.
The user's embedded wallet is automatically created or retrieved once the session is created and can be accessed via unity.
7. Get User Details and Portfolio
Use a BffClientRepository monobehavior to fetch user information:
8. Start Unity App
Run your app:-
- Open the OktoDemo scene in the project
- Click the Play button in the Unity Editor
- Test the authentication flow with your Google credentials
- Explore available functions like wallet info and token balances
9. Congratulations!
🎉 Your basic Okto integration is now complete! You're ready to bring your dApp to life. Let's try out a simple user operation!
Trying Out a User Operation
Now that we have our basic setup complete, let's implement a token transfer on Polygon Amoy Testnet to understand how user operations work in Okto.
2. Fund Your Wallet
To perform a token transfer, you'll need some funds in your wallet. Add funds to this address using the Polygon Amoy Faucet. You can verify your balance using the GetPortfolio()
method.
3. Check Network Information
Before creating the user operation, check the Network Information Guide for getting the correct CAIP-2 IDs of chains.
5. Verify The Transfer
After the transfer is complete, you can verify it through:
- The
GetPortfolio()
method to check your updated balance - The Polygon Explorer using the transaction hash
Now that you've completed your first user operation, you're ready to explore more advanced features! Check out our Usage Guide to learn about other operations like NFT transfers, contract interactions, and more.
For more examples and advanced usage, check out the Template Repo.
SDK Reference
Get Commands
Command | Description | Documentation |
---|---|---|
var account = await GetAccount(oktoClient); | Get user's wallet details | Method Overview |
var chains = await GetChains(oktoClient); | List supported blockchain networks | Method Overview |
var tokens = await getTokens(oktoClient); | List supported tokens | Method Overview |
var portfolio = await GetPortfolio(oktoClient); | Get user's token holdings | Method Overview |
var nfts = await GetPortfolioNFT(oktoClient); | Get user's NFT holdings | Method Overview |
var activity = await GetPortfolioActivity(oktoClient); | Get transaction history | Method Overview |
var orders = await GetOrdersHistory(oktoClient); | Get transaction order history | Method Overview |
var collections = await GetNftCollections(oktoClient); | Get NFT collections | Method Overview |
User Operations (Intents)
Intents are pre-built action templates within the Okto SDK that simplify common Web3 tasks. They provide one-liner functions for complex blockchain interactions.
1. Token Transfer
Send tokens to another address. Learn more
2. NFT Transfer
Transfer NFTs between addresses. Learn more
3. Raw Transaction (EVM)
Execute custom EVM contract calls. Learn more
Quick Start Template Available!
Skip the manual setup and get started in minutes with our template repository. It includes pre-configured Okto SDK integration, authentication setup, and example components and operations.
Additional Resources
Need help? Join our Discord community or email us at [email protected]
.