Streamlined Player Onboarding with Eidolon
In this section we’ll look at how we can use the WebGLWallet
class to interact with browser based wallets like MetaMask
, TrustWallet
and more. We’ll instantiate a new wallet and connect our player to a specified network.
Step 1: Instantiate a Wallet
To create a new wallet instance, follow these steps:
In the example above, we instantiate a new wallet and smart contract instance by providing the contract address and ABI of the smart contract we want to interact with. We then pass the wallet in the smart contract constructor to let Eidolon know we want to sign transactions with that wallet.
Step 2: Connect to a Network
Now, let’s connect the player to an example network, in this case, the SKALE Chaos Test Network. We will set the required network-specific information.
In this step, we set up the connection to the SKALE Calypso Test Network by providing the chain ID.
Step 3: Send a Test Transaction
Let’s send a test transaction to a smart contract using the wallet and smart contract instance. We use Named arguments to pass only the method name and arguments. You can however adjust the gas, gasPrice, value and nonce if required.
Here, we send a test transaction by calling a method on a smart contract with the provided parameters.
Step 5: Read Data from Smart Contract
To read data from a smart contract, use the Call
method asynchronously. In this example, we read the balance of an address.
In this step, we asynchronously read data from the smart contract and handle the result when the task is completed.
Conclusion
By following these steps, you can successfully use the Wallet
class to create a new wallet, connect a player to any EVM network, and interact with smart contracts in your Unity project. This allows you to integrate blockchain functionality into your game seamlessly.
In this section, we’ll explore two distinct methods for player onboarding using the Eidolon SDK. Whether you prefer a traditional interactive login approach or a seamless invisible login experience, Eidolon makes it easy to integrate Ethereum blockchain features into your game.
Interactive Login
Overview
The Interactive Login method allows players to sign up and log in using a familiar username and password system. Players can manage their accounts and store information securely. This approach provides flexibility for players to choose their credentials.
Code Example
Explanation
- The
InteractiveLogin
script provides a user-friendly interface for player account creation and login. - Players can enter their desired username and password in the input fields.
- The
SignUp
method creates a new account based on the provided credentials and handles success or failure accordingly. - The
Login
method loads the signer key for transaction signing upon successful login and sets it as the signer for transactions. - Gas balance checking and other necessary logic can be added to the
Login
method as required.
Invisible Login
Overview
The Invisible Login method generates a wallet ID and secret, securely stores it within the device keystore, and enables seamless background login flows without player input. This method is ideal for creating a frictionless player experience.
Code Example
Explanation
- The
InvisibleLogin
script allows developers to create and manage Ethereum accounts on behalf of players, enabling seamless background login flows. - In the
CreateAccount
method, a unique identifier (e.g., device ID) is used to identify the signer, and a secure secret is generated for the signer. - The
LoadAccount
method loads the private key using theSigner.Load
method based on the identifier. - Gas balance checking and other necessary logic can be added to the
LoadAccount
method as needed.
These examples showcase how Eidolon empowers developers to implement player onboarding mechanisms seamlessly, whether through traditional interactive login or frictionless invisible login experiences.