Skip to content

Using Wallets with Eidolon

The IWallet interface is used universally between Desktop, Mobile and WebGL builds. The only thing that differs is their constructors and recommended usage flow. Below we dive into how the interface is used for each platform!

When building for WebGL, the WebGLWallet class is compatible with most popular browser wallets following the JSON-RPC standard. It works seamlessly with wallets like MetaMask, TrustWallet, Enkrypt, and many others, providing users with a wide range of wallet options for interacting with your Unity-based blockchain game.

Constructor

The WebGLWallet class has a constructor that initializes a new instance. You can use this constructor to create instances of wallet providers for different blockchains. Both single-chain and multi-chain constructors are dynamic and work even if mixed together in the same script. Feel free to creatively use this to create awesome experiences.

Single-Chain Constructor

// You can provide an empty constructor to have the wallet inherit the RPC set with the Project Settings.
WebGLWallet myWallet = new WebGLWallet()

Example:

// Reference to your contract
WebGLWallet wallet;
public void Awake()
{
// Initialize an instance of the WebGLWallet class
WebGLWallet wallet = new WebGLWallet();
}

Once your wallet instance has been instantiated, you can use it to invoke functions like Connect, SwitchChains, SendTransaction and so much more!

Multi-Chain Constructor

// Alternatively you can override the default RPC to instantiate a Wallet instance on a different network
// Custom RPC Provider
JsonRpcProvider provider = new JsonRpcProvider(" customRpcHere")
WebGLWallet myWallet = WebGLWallet(provider);
  • provider (JsonRpcProvider): The RPC (Remote Procedure Call) endpoint URL of the blockchain network.

Example:

// Reference to your wallets
WebGLWallet ethereumWallet;
WebGLWallet skaleWallet;
public void Awake()
{
// Create new JsonRpcProvider instances to be used for the differen networks.
JsonRpcProvider ethRpc = new JsonRpcProvider("EthRpcHere");
JsonRpcProvider skaleRpc = new JsonRpcProvider("SkaleRpcHere");
// All of the below instances will use the RPC passed in the constructor.
// Initialize an instance of your wallet on the Ethereum network
ethereumWallet = new WebGLWallet(ethRpc);
// Initialize an instance of your wallet on the SKALE network
skaleWallet = new WebGLWallet(skaleRpc);
// Let's use our instances
// Use your Ethereum wallet instance to connect to the users default browser wallet to Ethereum
string account = ethereumWallet.Connect("1");
// Debug the account (optional)
Debug.Log("Connected Account: " + account);
}

With the multi-chain constructor, you can connect to different blockchains and interact with smart contracts on those networks. It allows you to set a default network using the Project Setup window, whilst still allowing you to interact with contracts on other networks.

Methods

After instantiating your WebGLWallet instance, you can utilize any of the below wallet methods anywhere in your Unity project.

Connect

Connect(string chainId)
Method Description

Connects the wallet provider to a specific Ethereum network using the provided chain ID. THis function will return the connected public address.

Code Example
string chainId = "1"; // Main Ethereum Network (Change to the desired chain ID)
string account = wallet.Connect(chainId);
Debug.Log("Connected Account: " + account);
Parameter Explanation
  • chainId (string): The chain ID of the target network.

Connect (Overload)

Connect(string chainId, string rpcUrl, string chainName, string nativeCurrencyName, string nativeCurrencySymbol, string nativeCurrencyDecimals, string blockExplorer)
Method Description

Connects the wallet provider to a specific network, adding the network if it’s not available on the users browser wallet. This function will return the connected public address.

Code Example
string chainId = "1351057110"; // SKALE Calypso Test Network (Change to the desired chain ID)
string rpcUrl = "https://testnet.skalenodes.com/v1/giant-half-dual-testnet"; // Replace with your RPC URL
string chainName = "SKALE Calypso Testnet";
string nativeCurrencyName = "sFUEL";
string nativeCurrencySymbol = "sFUEL";
string nativeCurrencyDecimals = "18";
string blockExplorer = "https://giant-half-dual-testnet.explorer.testnet.skalenodes.com/";
string account = wallet.Connect(chainId, rpcUrl, chainName, nativeCurrencyName, nativeCurrencySymbol, nativeCurrencyDecimals, blockExplorer);
Debug.Log("Connected Account: " + account);
Parameter Explanation
  • chainId (string): The chain ID of the target network.
  • rpcUrl (string): The RPC URL of the network.
  • chainName (string): The name of the network.
  • nativeCurrencyName (string): The native currency name.
  • nativeCurrencySymbol (string): The native currency symbol.
  • nativeCurrencyDecimals (string): The number of decimals for the native currency.
  • blockExplorer (string): The URL of the block explorer for the network.

SwitchChains

SwitchChains(string chainId)
Method Description

Switches the connected Ethereum network to a different one using the specified chain ID.

Code Example
string chainId = "1351057110"; // SKALE Calypso Test Network (Change to the desired chain ID)
wallet.SwitchChains(chainId);
Parameter Explanation
  • chainId (string): The chain ID of the target network.

SwitchChains (Overload)

SwitchChains(string chainId, string rpcURL, string chainName, string nativeCurrencyName, string nativeCurrencySymbol, string nativeCurrencyDecimals, string blockExplorer)
Method Description

Switches the connected network, adding the network if it’s not available on the users browser wallet.

Code Example
string chainId = "1564830818"; // SKALE Calyspo Mainnet Network (Change to the desired chain ID)
string rpcURL = "https://mainnet.skalenodes.com/v1/honorable-steel-rasalhague"; // Replace with your RPC URL
string chainName = "SKALE Calypso Mainnet";
string nativeCurrencyName = "sFUEL";
string nativeCurrencySymbol = "sFUEL";
string nativeCurrencyDecimals = "18";
string blockExplorer = "https://honorable-steel-rasalhague.explorer.mainnet.skalenodes.com/";
wallet.SwitchChainsAndAdd(chainId, rpcURL, chainName, nativeCurrencyName, nativeCurrencySymbol, nativeCurrencyDecimals, blockExplorer);
Parameter Explanation
  • chainId (string): The chain ID of the target network.
  • rpcURL (string): The RPC URL of the network.
  • chainName (string): The name of the network.
  • nativeCurrencyName (string): The native currency name.
  • nativeCurrencySymbol (string): The native currency symbol.
  • nativeCurrencyDecimals (string): The number of decimals for the native currency.
  • blockExplorer (string): The URL of the block explorer for the network.

Disconnect

Disconnect()
Method Description

Disconnects from the currently connected wallet and clears the account information.

Code Example
wallet.Disconnect();

GetTransactionReceipt

GetTransactionReceipt()
Method Description

Retrieves the transaction receipt after sending a transaction.

Code Example
string transactionReceipt = wallet.GetTransactionReceipt();
Debug.Log("Transaction Receipt: " + transactionReceipt);
Parameter Explanation
  • None

GetChainId

GetChainId()
Method Description

Retrieves the users current connected chain ID.

Code Example
string chainId = wallet.GetChainId();
Debug.Log("Current Chain: " + chainId);
Parameter Explanation
  • None

SendTransaction

SendTransaction(string to, string gas = null, string gasPrice = null, string value = null, string nonce = null, string data = null)
Method Description

Sends a transaction to a smart contract method. Parameters like gas, gasPrice and value are optional. This function will return a transaction hash if successful, or an exception if not.

Code Example
// Transfer 1 ETH to a user address by specifying the to address and the value in ETH.
string transactionHash = wallet.SendTransaction("WalletAddressHere", value: "1");
Parameter Explanation
  • to (string): The address your sending the transaction to.
  • gas (optional) (string): The gas limit for the transaction.
  • gasPrice (optional) (string): The gas price for the transaction.
  • value (optional) (string): The value for chain native tokens.
  • nonce (optional) (string): The current transaction nonce count.
  • data (optional): The encoded data for a contract method and set of parameters.

Sign Message

SignMessage(string message)
Method Description

Prompts the connected account to sign a message.

Code Example
// Prompt the connected account to sign a message and return the signature.
string signature = wallet.SignMessage("This is a test message!");
Parameter Explanation
  • message (string): The message data you want the user to sign.