Privy but in Unity! A comprehensive Unity SDK for integrating Privy authentication and embedded wallet functionality into your Unity games and applications.
- ๐ Email Authentication - Passwordless email login with verification codes
- ๐ OAuth Support - Sign in with Apple and other OAuth providers
- ๐ผ Embedded Wallets - Create and manage Ethereum and Solana wallets
- ๐ฑ Multi-Platform Support - iOS, WebGL, and Editor support
- ๐ Smart Contract Integration - Send transactions, call contracts, and interact with the blockchain
- ๐ฐ Wallet Management - Get balances, sign messages, and manage transactions
- ๐ฎ Unity Integration - Prefabs and scripts ready to use in your Unity projects
- Unity 6000.0 or higher
- Privy account with App ID and Client IDs
- For iOS: Xcode and iOS development setup
- For WebGL: Unity WebGL build support
- Add this package to your Unity project via the Package Manager
- Import the package into your Unity project
- Configure your Privy credentials (see Configuration section)
- Drag the
Privy.prefabfrom thePrefabsfolder into your scene - Or create an empty GameObject and add the
PrivyControllercomponent
In the PrivyController component, set:
- App ID: Your Privy App ID
- Mobile Client ID: Your mobile client ID (used in Editor)
- Web Client ID: Your web client ID (used in WebGL builds)
- Create Wallet On Login: Whether to automatically create a wallet when user logs in
PrivyController privyController = FindFirstObjectByType<PrivyController>();
await privyController.SendCode("[email protected]");await privyController.LoginWithCode("[email protected]", "123456");PrivyUser user = await PrivyManager.Instance.GetUser();
IEmbeddedEthereumWallet wallet = user.EmbeddedWallets[0];
string address = wallet.Address;- Create a Privy account at privy.io
- Create a new app in the Privy dashboard
- Get your App ID and Client IDs
- Configure allowed app identifiers for your platforms
In your PrivyController:
- App ID: Your Privy App ID from the dashboard
- Mobile Client ID: OAuth client ID for mobile platforms (iOS)
- Web Client ID: OAuth client ID for WebGL builds
public class LoginExample : MonoBehaviour
{
private PrivyController privyController;
void Start()
{
privyController = FindFirstObjectByType<PrivyController>();
}
public async void OnSendCodeClicked()
{
await privyController.SendCode("[email protected]");
}
public async void OnLoginClicked(string email, string code)
{
await privyController.LoginWithCode(email, code);
}
}PrivyUser user = await PrivyManager.Instance.GetUser();
IEmbeddedEthereumWallet wallet = user.EmbeddedWallets[0];
var rpcRequest = new RpcRequest
{
Method = "personal_sign",
Params = new string[] { "Hello, World!", wallet.Address }
};
RpcResponse response = await wallet.RpcProvider.Request(rpcRequest);
Debug.Log($"Signature: {response.Data}");// Send ETH
privyController.SendTransaction(
to: "0xRecipientAddress",
data: "0x",
value: "0x186a0" // 100000 wei in hex
);
// Call a smart contract function
privyController.SendTransaction(
to: "0xContractAddress",
data: "0xFunctionData",
value: "0x0"
);string balanceHex = await privyController.GetBalance();
decimal balanceEth = SmartContractHelper.WeiToEth(balanceHex);
Debug.Log($"Balance: {balanceEth} ETH");// Read from contract (call)
privyController.CallContract(
to: "0xContractAddress",
data: "0xFunctionData"
);
// Write to contract (transaction)
privyController.SendTransaction(
to: "0xContractAddress",
data: "0xFunctionData",
value: "0x0"
);// Validate chain before sending transaction
bool isValid = await privyController.ValidateChain("0x1"); // Ethereum mainnet
if (isValid)
{
privyController.SendTransaction(to, data, value);
}
// Or use the convenience method
privyController.SendTransactionWithChainValidation(
to: "0xContractAddress",
data: "0xFunctionData",
value: "0x0",
expectedChainId: "0x1"
);The SDK includes several ready-to-use prefabs:
- Privy.prefab - Main Privy controller with initialization
- Privy User Id Text.prefab - Displays the current user ID
- Privy User Wallet Text.prefab - Displays the wallet address
- Privy User Wallet Balance.prefab - Displays the wallet balance
- Native Apple Sign In support
- ASWebAuthenticationSession for OAuth flows
- Full embedded wallet functionality
- Popup-based OAuth flows
- Iframe-based wallet interactions
- Full blockchain interaction support
- Development and testing support
- Uses mobile client ID for OAuth flows
Main entry point for Privy functionality.
// Initialize Privy
PrivyManager.Initialize(config);
// Get current user
PrivyUser user = await PrivyManager.Instance.GetUser();
// Email authentication
bool success = await PrivyManager.Instance.Email.SendCode(email);
AuthState state = await PrivyManager.Instance.Email.LoginWithCode(email, code);Represents an authenticated Privy user.
// Get user ID
string userId = user.Id;
// Get embedded wallets
IEmbeddedEthereumWallet[] wallets = user.EmbeddedWallets;
// Create a new wallet
await user.CreateWallet();Interface for Ethereum wallet operations.
// Get wallet address
string address = wallet.Address;
// Get current chain ID
string chainId = wallet.ChainId;
// Make RPC calls
RpcResponse response = await wallet.RpcProvider.Request(rpcRequest);Supported Ethereum RPC methods:
personal_sign- Sign messageseth_sendTransaction- Send transactionseth_call- Call contract functionseth_getBalance- Get wallet balanceeth_gasPrice- Get current gas priceeth_signTypedData_v4- Sign typed data- And more...
Check out the Demo.unity scene in the Scenes folder for a complete working example of:
- Email authentication flow
- Wallet creation and management
- Smart contract interactions
- Balance checking
- Transaction sending
- Verify your App ID is correct in the PrivyController
- Ensure the App ID matches your Privy dashboard
- Check that your Client IDs are set correctly
- Verify the client IDs match your platform (mobile vs web)
- Add your app's bundle identifier to the Privy dashboard
- For iOS: Add your bundle ID
- For WebGL: Add your domain
- Ensure user is authenticated before creating wallet
- Check network connectivity
- Verify Privy dashboard settings allow wallet creation
- For iOS: Ensure proper entitlements and Info.plist configuration
- For WebGL: Check popup blockers and browser permissions
- Verify OAuth provider is configured in Privy dashboard
Contributions are welcome! Please feel free to submit a Pull Request.
See LICENSE.md for details.
See Third Party Notices.md for information about third-party software used in this package.
For issues, questions, or feature requests:
- Email: [email protected]
- Website: https://jacobhomanics.com
Jacob Homanics
- Email: [email protected]
- Website: https://jacobhomanics.com