diff --git a/docs/v2.5/11_interacting-with-smart-contracts.md b/docs/v2.5/10_interacting-with-smart-contracts.md similarity index 99% rename from docs/v2.5/11_interacting-with-smart-contracts.md rename to docs/v2.5/10_interacting-with-smart-contracts.md index faa14ef9..3c7088e4 100644 --- a/docs/v2.5/11_interacting-with-smart-contracts.md +++ b/docs/v2.5/10_interacting-with-smart-contracts.md @@ -1,6 +1,6 @@ --- slug: /current/interacting-with-smart-contracts -sidebar_position: 11 +sidebar_position: 10 sidebar_label: Interacting With Smart Contracts --- diff --git a/docs/v2.5/12_web2-like-authentication-using-web3auth.md b/docs/v2.5/11_web2-like-authentication-using-web3auth.md similarity index 99% rename from docs/v2.5/12_web2-like-authentication-using-web3auth.md rename to docs/v2.5/11_web2-like-authentication-using-web3auth.md index fdd8a558..440fef69 100644 --- a/docs/v2.5/12_web2-like-authentication-using-web3auth.md +++ b/docs/v2.5/11_web2-like-authentication-using-web3auth.md @@ -1,6 +1,6 @@ --- slug: /current/web2-like-authentication-using-web3auth -sidebar_position: 12 +sidebar_position: 11 sidebar_label: Web2-Like Authentication Using Web3Auth --- diff --git a/docs/v2.5/13_gasless-transactions-using-gelato.md b/docs/v2.5/12_gasless-transactions-using-gelato.md similarity index 99% rename from docs/v2.5/13_gasless-transactions-using-gelato.md rename to docs/v2.5/12_gasless-transactions-using-gelato.md index 0bf12689..204d7d0e 100644 --- a/docs/v2.5/13_gasless-transactions-using-gelato.md +++ b/docs/v2.5/12_gasless-transactions-using-gelato.md @@ -1,6 +1,6 @@ --- slug: /current/gasless-transactions-using-Gelato -sidebar_position: 13 +sidebar_position: 12 sidebar_label: Gasless Transactions Using Gelato --- diff --git a/docs/v2.5/14_extending-the-sdk.md b/docs/v2.5/13_extending-the-sdk.md similarity index 99% rename from docs/v2.5/14_extending-the-sdk.md rename to docs/v2.5/13_extending-the-sdk.md index 7f7e0951..0fe954b9 100644 --- a/docs/v2.5/14_extending-the-sdk.md +++ b/docs/v2.5/13_extending-the-sdk.md @@ -1,6 +1,6 @@ --- slug: /current/extending-the-sdk -sidebar_position: 14 +sidebar_position: 13 sidebar_label: Extending The SDK --- diff --git a/docs/v2.5/15_lootboxes.md b/docs/v2.5/14_lootboxes.md similarity index 99% rename from docs/v2.5/15_lootboxes.md rename to docs/v2.5/14_lootboxes.md index 3161b936..d57827f9 100644 --- a/docs/v2.5/15_lootboxes.md +++ b/docs/v2.5/14_lootboxes.md @@ -1,6 +1,6 @@ --- slug: /current/lootboxes -sidebar_position: 15 +sidebar_position: 14 sidebar_label: Lootboxes --- diff --git a/docs/v2.5/16_block-racers-game.md b/docs/v2.5/15_block-racers-game.md similarity index 99% rename from docs/v2.5/16_block-racers-game.md rename to docs/v2.5/15_block-racers-game.md index 0681cebb..0da61757 100644 --- a/docs/v2.5/16_block-racers-game.md +++ b/docs/v2.5/15_block-racers-game.md @@ -1,6 +1,6 @@ --- slug: /current/block-racers-game -sidebar_position: 16 +sidebar_position: 15 sidebar_label: Block Racers Game --- diff --git a/docs/v2.5/17_faq.md b/docs/v2.5/16_faq.md similarity index 99% rename from docs/v2.5/17_faq.md rename to docs/v2.5/16_faq.md index 4498b3a4..aaff9fd0 100644 --- a/docs/v2.5/17_faq.md +++ b/docs/v2.5/16_faq.md @@ -1,6 +1,6 @@ --- slug: /current/faq -sidebar_position: 17 +sidebar_position: 16 sidebar_label: FAQ --- diff --git a/docs/v2.5/1_getting-started.md b/docs/v2.5/1_getting-started.md index 4343892e..2cf284b5 100644 --- a/docs/v2.5/1_getting-started.md +++ b/docs/v2.5/1_getting-started.md @@ -32,6 +32,9 @@ This page will walk you through the process of setting up a project ID and using ![](v2Assets/openupmInstall.png) 5. Packages will be installed and the SDK will be available to you. +### Updating via The Package Manager +Updating the SDK is easy. Simply go to window -> package manager -> select the ChainSafe SDK package & press update. The same can be done for any additional packages you have installed, web3auth, lootboxes etc. + ### Set Project ID As the package is installed, you'll be prompted with settings window. diff --git a/docs/v2.5/6_connecting-a-wallet.md b/docs/v2.5/6_connecting-a-wallet.md new file mode 100644 index 00000000..890e80c3 --- /dev/null +++ b/docs/v2.5/6_connecting-a-wallet.md @@ -0,0 +1,115 @@ +--- +slug: /current/connecting-a-wallet +sidebar_position: 6 +sidebar_label: Connecting A Wallet +--- + + +# Connecting a Wallet + +:::info + +This page teaches you how to connect a wallet and our how our system is initialized. + +::: + +There is no separate state to connect player wallet. Connection procedure is triggered as part +of Web3 build process. This is due to the fact that after Web3 build process is completed, your Web3 instance +and all of it's components have to have their states fully initialized. Starting from this point you can safely +use each and every component and not worry you missed an initialization step. + +In simple words, wallet connection happens when you call `LaunchAsync()` on `Web3Builder` object. +So, to handle connection error as well as any other initialization error you should wrap `LaunchAsync` +call into a try/catch statement. Alternatively you can just use the login scene provided with the samples and it will do all of this for you. + +```csharp +using System; +using System.Collections; +using System.Threading.Tasks; +using ChainSafe.Gaming.Evm.Contracts; +using ChainSafe.Gaming.Evm.JsonRpc; +using ChainSafe.Gaming.MultiCall; +using ChainSafe.Gaming.UnityPackage; +using ChainSafe.Gaming.Web3; +using ChainSafe.Gaming.Web3.Build; +using ChainSafe.Gaming.Web3.Unity; +using ChainSafe.GamingSdk.Gelato; +using Scripts.EVM.Token; +using UnityEngine; +using UnityEngine.SceneManagement; + +namespace Scenes +{ + public abstract class Login : MonoBehaviour + { + // Set this to your main scene + public const string MainSceneName = "SampleMain"; + + public static int LoginSceneIndex { get; private set; } = 0; + + [SerializeField] private string gelatoApiKey = ""; + + [SerializeField] private ErrorPopup errorPopup; + + private IEnumerator Start() + { + yield return Initialize(); + } + + protected abstract IEnumerator Initialize(); + + protected abstract Web3Builder ConfigureWeb3Services(Web3Builder web3Builder); + + protected async Task TryLogin() + { + Web3 web3; + + try + { + Web3Builder web3Builder = new Web3Builder(ProjectConfigUtilities.Load()) + .Configure(ConfigureCommonServices); + + web3Builder = ConfigureWeb3Services(web3Builder); + + web3 = await web3Builder.LaunchAsync(); + } + + catch (Exception) + { + errorPopup.ShowError("Login failed, please try again\n(see console for more details)"); + throw; + } + + Web3Accessor.Set(web3); + + LoginSceneIndex = SceneManager.GetActiveScene().buildIndex; + + SceneManager.LoadScene(MainSceneName); + } + + private void ConfigureCommonServices(IWeb3ServiceCollection services) + { + services + .UseUnityEnvironment() + .UseGelato(gelatoApiKey) + .UseMultiCall() + .UseRpcProvider(); + + /* As many contracts as needed may be registered here. + * It is better to register all contracts the application + * will be interacting with at configuration time if they + * are known in advance. We're just registering shiba + * here to show how it's done. You can look at the + * `Scripts/Prefabs/Wallet/RegisteredContract` script + * to see how it's used later on. + */ + services.ConfigureRegisteredContracts(contracts => + contracts.RegisterContract("CsTestErc20", ABI.Erc20, Contracts.Erc20)); + + } + } +} +``` + +It also makes sense to retry building the Web3 object when the connection +fails. It's up to you if you wanna do it automatically or when a player presses the button. \ No newline at end of file diff --git a/docs/v2.5/6_signers-and-wallets.md b/docs/v2.5/6_signers-and-wallets.md deleted file mode 100644 index 340b1bb9..00000000 --- a/docs/v2.5/6_signers-and-wallets.md +++ /dev/null @@ -1,103 +0,0 @@ ---- -slug: /current/signers-and-wallets -sidebar_position: 6 -sidebar_label: Signers And Wallets ---- - - -# Signers and Wallets - -:::info - -This page explains signers and how we've utilized them within the new SDK. - -::: - -As we learned in the previous section wallet is essentially Signer + Transaction executor. -Meaning it has access to key pairs of the currently active user and it can also send a transaction -for execution. - -It's not always the case, but when it is, you should use `Use$Name$Wallet()` to bind the wallet implementation. -This would bind both Signer & Transaction Executor. - -There are 2 implementations of wallet available at the moment: WebPageWallet and WebGLWallet. - -### WebPageWallet - -WebPageWallet is a cross-platform implementation, that you can use on most platforms. -It works by opening up a new browser page which delegates all calls to a wallet extension installed -in the browser. User than copies the result of the operation and when he comes back to the game, -result is read from the buffer and operation completes. - -You can bind it with `services.UseWebPageWallet()`: -```csharp -using ChainSafe.Gaming.Build; -using ChainSafe.Gaming.Wallets.WebPage; - -var web3 = await new Web3Builder(projectConfig) - .Configure(services => - { - ... - services.UseWebPageWallet(); - }) - .BuildAsync(); -``` - -You can also configure WebPageWallet like this: - -```csharp -services.UseWebPageWallet( - new WebPageWalletConfig - { - // Build a message that will be shown to user when he's prompted to sign a message - ConnectMessageBuilder = expireTime => $"Sign me till {expireTime:hh:mm:ss}}", - - // Timeout for a wallet connection request - ConnectRequestExpiresAfter = TimeSpan.FromMinutes(5), - - // Provide last connected user address if you want to skip authentication - SavedUserAddress = lastUserAddress, - - // How often should we check clipboard for the result - ClipboardCheckPeriod = TimeSpan.FromSeconds(0.1f), - - // Provide your own web service instead of Chainsafe's (complex topic) - ServiceUrl = "myawesomegame.com/webpagewallet" - }); -``` - -Notice `SavedUserAddress` property. You can use it to enable 'Remember Me' option for your players. -If a player enabled the 'Remember Me' toggle, store his public address somewhere and provide it -using `SavedUserAddress` next time when he starts the game. -Send null if you want to initiate wallet connection process. - -Note: We know this is not the best cross-platform wallet implementation, but that's the only one -available at the moment. Don't worry we are already working on a new, better version ;) - -### WebGLWallet - -Use WebGLWallet if you're targeting WebGL platform. When user first connects his account, -he'll be prompted to choose the wallet software. Later on all signing and sending operations -will be delegated to this wallet. - -![](v2Assets/webgl-available-wallets.png) - -To bind WebGLWallet call `services.UseWebGLWallet()`: -```csharp -using ChainSafe.Gaming.Build; -using ChainSafe.Gaming.Wallets.WebGLWallet; - -var web3 = await new Web3Builder(projectConfig) - .Configure(services => - { - ... - services.UseWebGLWallet(); - }) - .BuildAsync(); -``` - -### Web3AuthSigner - -In version 2.5 we've introduced a new type of signer. It provides simple Web2 like authentication -user experience for those who are new to ethereum or just don't wanna spend time creating new wallets. -You can learn what is Web3Auth and how to integrate it into your project using this link [here](https://docs.gaming.chainsafe.io/current/web2-like-authentication-using-web3auth). \ No newline at end of file diff --git a/docs/v2.5/7_connecting-a-wallet.md b/docs/v2.5/7_connecting-a-wallet.md deleted file mode 100644 index bbf76cb2..00000000 --- a/docs/v2.5/7_connecting-a-wallet.md +++ /dev/null @@ -1,103 +0,0 @@ ---- -slug: /current/connecting-a-wallet -sidebar_position: 7 -sidebar_label: Connecting A Wallet ---- - - -# Connecting a Wallet - -:::info - -This page teaches you how to connect a wallet and our how our system is initialized. - -::: - -There is no separate state to connect player wallet. Connection procedure is triggered as part -of Web3 build process. This is due to the fact that after Web3 build process is completed, your Web3 instance -and all of it's components have to have their states fully initialized. Starting from this point you can safely -use each and every component and not worry you missed an initialization step. - -In simple words, wallet connection happens when you call `BuildAsync()` on `Web3Builder` object. -So, to handle connection error as well as any other initialization error you should wrap `BuildAsync` -call into a try/catch statement. - -```csharp -using System.Threading.Tasks; -using ChainSafe.Gaming.Web3.Build; -using ChainSafe.Gaming.Evm.JsonRpc; -using ChainSafe.Gaming.UnityPackage; -using ChainSafe.Gaming.Wallets; -using ChainSafe.Gaming.Web3; -using ChainSafe.Gaming.Web3.Unity; -using UnityEngine.SceneManagement; -using UnityEngine; - -/// -/// A login script that allows you to connect to metamask -/// -public class Login : MonoBehaviour -{ - // Variables - private Web3 web3; - private Web3Builder builder; - private bool useWebPageWallet; - - /// - /// Used to initialize connection to a wallet, put this call in the start function or on a button event - /// - public async void Connect() - { - useWebPageWallet = Application.platform != RuntimePlatform.WebGLPlayer; - builder = new Web3Builder(ProjectConfigUtilities.Load()) - .Configure(ConfigureCommonServices) - .Configure(services => - { - if (useWebPageWallet) - { - services.UseWebPageWallet(); - } - else - { - services.UseWebGLWallet(); - } - }); - await ProcessConnection(); - } - - /// - /// Processes the connection and sets the users wallet for later calls - /// - private async Task ProcessConnection() - { - Debug.Log("Connecting"); - try - { - web3 = await builder.BuildAsync(); - Web3Accessor.Set(web3); - PlayerPrefs.SetString("PlayerAccount", await Web3Accessor.Web3.Signer.GetAddress()); - Debug.Log("Connected!"); - SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1); - } - catch (Web3Exception e) - { - Debug.Log(e + "Connection failed. Try again."); - throw; - } - } - - /// - /// Standard configuration needed - /// - /// - private void ConfigureCommonServices(IWeb3ServiceCollection services) - { - services - .UseUnityEnvironment() - .UseRpcProvider(); - } -} -``` - -It also makes sense to retry building the Web3 object when the connection -fails. It's up to you if you wanna do it automatically or when a player presses the button. \ No newline at end of file diff --git a/docs/v2.5/8_interacting-with-tokens.md b/docs/v2.5/7_interacting-with-tokens.md similarity index 99% rename from docs/v2.5/8_interacting-with-tokens.md rename to docs/v2.5/7_interacting-with-tokens.md index 80d8c78e..dd3ed9c1 100644 --- a/docs/v2.5/8_interacting-with-tokens.md +++ b/docs/v2.5/7_interacting-with-tokens.md @@ -1,6 +1,6 @@ --- slug: /current/interacting-with-tokens -sidebar_position: 8 +sidebar_position: 7 sidebar_label: Interacting With Tokens --- diff --git a/docs/v2.5/9_interacting-with-nfts.md b/docs/v2.5/8_interacting-with-nfts.md similarity index 99% rename from docs/v2.5/9_interacting-with-nfts.md rename to docs/v2.5/8_interacting-with-nfts.md index 9f74d700..1e86b062 100644 --- a/docs/v2.5/9_interacting-with-nfts.md +++ b/docs/v2.5/8_interacting-with-nfts.md @@ -1,6 +1,6 @@ --- slug: /current/interacting-with-nfts -sidebar_position: 9 +sidebar_position: 8 sidebar_label: Interacting With NFTs --- diff --git a/docs/v2.5/10_voucher-minting-nfts.md b/docs/v2.5/9_voucher-minting-nfts.md similarity index 99% rename from docs/v2.5/10_voucher-minting-nfts.md rename to docs/v2.5/9_voucher-minting-nfts.md index 393d43a1..52683c6b 100644 --- a/docs/v2.5/10_voucher-minting-nfts.md +++ b/docs/v2.5/9_voucher-minting-nfts.md @@ -1,6 +1,6 @@ --- slug: /current/voucher-minting-nfts -sidebar_position: 10 +sidebar_position: 9 sidebar_label: Voucher Minting NFTs --- diff --git a/sidebars.js b/sidebars.js index 2feaafad..ad429329 100644 --- a/sidebars.js +++ b/sidebars.js @@ -10,8 +10,8 @@ module.exports = { 'chainsafe-gaming', { type: 'category', - label: 'Current SDK Documentation (v2.5.1)', - items: ['v2.5/getting-started', 'v2.5/project-id-registration', 'v2.5/setting-up-an-rpc-node', 'v2.5/configuration', 'v2.5/signers-and-wallets', 'v2.5/connecting-a-wallet', 'v2.5/interacting-with-tokens', 'v2.5/interacting-with-nfts', 'v2.5/voucher-minting-nfts', 'v2.5/interacting-with-smart-contracts', 'v2.5/web2-like-authentication-using-web3auth', 'v2.5/gasless-transactions-using-gelato', 'v2.5/extending-the-sdk', 'v2.5/lootboxes', 'v2.5/block-racers-game', 'v2.5/prefab-scripts', 'v2.5/faq'], + label: 'Current SDK Documentation (v2.5.3)', + items: ['v2.5/getting-started', 'v2.5/project-id-registration', 'v2.5/setting-up-an-rpc-node', 'v2.5/configuration', 'v2.5/connecting-a-wallet', 'v2.5/interacting-with-tokens', 'v2.5/interacting-with-nfts', 'v2.5/voucher-minting-nfts', 'v2.5/interacting-with-smart-contracts', 'v2.5/web2-like-authentication-using-web3auth', 'v2.5/gasless-transactions-using-gelato', 'v2.5/extending-the-sdk', 'v2.5/lootboxes', 'v2.5/block-racers-game', 'v2.5/prefab-scripts', 'v2.5/faq'], }, { type: 'category',