Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V3 updates #144

Merged
merged 49 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
b1e9316
Included WebGL Metamask template in Metamask page
JAlbertCode Jun 12, 2024
33f03a2
Merge branch 'main' of https://github.com/ChainSafe/game-docs-v2
JAlbertCode Jul 10, 2024
c1bdb5a
Merge branch 'main' of https://github.com/ChainSafe/game-docs-v2
JAlbertCode Oct 2, 2024
eebf090
Updated wallet table to rename wallet connect to reown
JAlbertCode Oct 3, 2024
c965293
Updated references to Wallet Connect to reown
JAlbertCode Oct 3, 2024
6e47621
Removed all references of Wallet Connect
JAlbertCode Oct 3, 2024
c3e9b6f
Added add wallets to your unity game in the wallet page
JAlbertCode Oct 3, 2024
fbe3b88
Added image to wallet provider selection and clearer text.
JAlbertCode Oct 3, 2024
16787b8
Added wallet connect reference to Reown mentions
JAlbertCode Oct 6, 2024
cf7c05c
Updated check for browsers on Reown
JAlbertCode Oct 6, 2024
8695d23
removed scene info from Metamask page and updated content for WebGL B…
JAlbertCode Oct 6, 2024
29dae2d
Changed webgl to web3.unity in the resolution settings
JAlbertCode Oct 6, 2024
274000f
Updated navigation to reown content
JAlbertCode Oct 6, 2024
e218b75
Updated reown page with current images
JAlbertCode Oct 6, 2024
797048a
Updating the getting started to make sure that all the info stays rel…
kantagara Oct 7, 2024
60d0197
ABI C# Converter
kantagara Oct 7, 2024
ac0536d
Added generator to the sidebar naming
kantagara Oct 7, 2024
2d1cc28
Erc20contract
kantagara Oct 7, 2024
46ea631
Removed scene instructions from web3auth page
JAlbertCode Oct 7, 2024
86172ed
Removed hyperplay scene instructions
JAlbertCode Oct 7, 2024
21004ac
Updated images and content for Chainstack
JAlbertCode Oct 7, 2024
f2ec5a3
Removed bunch of samples from the sample scripts and chain interactio…
kantagara Oct 8, 2024
9fe9c4f
Marketplace tutorial.
kantagara Oct 8, 2024
68d547e
Updated the wallet overview docs to match what's in the dev branch fo…
JAlbertCode Oct 8, 2024
a0da5fd
Added a What is Metamask section to make the wallet pages consistent
JAlbertCode Oct 8, 2024
966d427
Added a what is reown section for consistency
JAlbertCode Oct 8, 2024
c5d4c33
Updated editor image for reown
JAlbertCode Oct 9, 2024
bd6f0ff
Re-added IPFS samples.
kantagara Oct 9, 2024
d2a5d0c
Docs now don't rely on samples. Introduced the Web3Auth wallet gui in…
kantagara Oct 9, 2024
b2f62a6
Added `MUD Autonomous Worlds` page
creeppak Oct 9, 2024
eadc2be
login process updated
rob1997 Oct 9, 2024
113bec7
Added content for 'MUD Autonomous Worlds' page
creeppak Oct 9, 2024
8cb3450
Merge branch 'v3-updates' of github.com-creeppak:ChainSafe/game-docs-…
creeppak Oct 9, 2024
b2dd56c
Listenting to blockchain events, Chain Switching
kantagara Oct 9, 2024
5df2f6c
Added MUD in sidebar.
kantagara Oct 9, 2024
db69bbb
Removed marketplace from the extensions part.
kantagara Oct 9, 2024
c134db5
checkpoint
rob1997 Oct 9, 2024
bf1f8f4
Merge branch 'v3-updates' of https://github.com/ChainSafe/game-docs-v…
rob1997 Oct 9, 2024
e9fed84
service adapter docs added
rob1997 Oct 9, 2024
6597285
better links
rob1997 Oct 9, 2024
1816bfc
better link for marketplace
rob1997 Oct 9, 2024
5a69b0b
Updated marketplace docs to also include the UI representation of the…
kantagara Oct 9, 2024
1605564
Merge branch 'v3-updates' of https://github.com/ChainSafe/game-docs-v…
kantagara Oct 9, 2024
1c7a380
added WebGL build exception fix faq
rob1997 Oct 9, 2024
1a143f9
Merge branch 'v3-updates' of https://github.com/ChainSafe/game-docs-v…
rob1997 Oct 9, 2024
16a572a
Added bunch of stuff to dictionary to prevent linter to go mad. Added…
kantagara Oct 9, 2024
fdc19c3
openUPM in dict
kantagara Oct 9, 2024
bd75096
nfts
kantagara Oct 9, 2024
1143c4c
reverted packages.json
kantagara Oct 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
A1
A2
ABI
ABIs
Addons
addons
addon
Expand All @@ -18,7 +19,10 @@ analytics
async
APIs
AppStore
Appkit
AppKit
auth
abi-to-csharp-converter
AUTH
backend
BalanceOf
Expand All @@ -31,6 +35,7 @@ blockchain
Blockchain
blockchains
Blockchains
blockchain-events
BSC
BuyItemWebGL
BuyItemWebWallet
Expand All @@ -55,6 +60,8 @@ chainID
ChainId
chainsafe
ChainSafe
Chainsafe
Chainsafes
ChainSafe's
Chainstack
ChainID's
Expand All @@ -63,6 +70,7 @@ cheatsheet
CLI
Cloudflare
config
Config
contract-abi-to-json-format
contractAbi
convert-wei-to-eth-and-eth-to-wei
Expand All @@ -77,7 +85,9 @@ DApp
devs
dev
devsetup
dropdown
ECDSA
Erc20Contract
erc20NameOf
EVM-compatible
EVM-compatible
Expand Down Expand Up @@ -128,9 +138,11 @@ goerli
Goerli
goerli's
GasLimit
Gamers
getter
gamers
gameplay
GameObject
GitHub
github
Goerli's
Expand Down Expand Up @@ -175,7 +187,9 @@ mainnets
mainnetgoerli
metamask
MetaMask
Metamask
Multicall
MultiCall
multicall
minter-evm
minting-nft
Expand All @@ -188,18 +202,22 @@ NewtonSoft
newtonsoft
non-EVM
NFT
NFTS
NFTPixels
nft-textures
NFT's
NFTPixels
NFTs
nfts
nodeJS
NodeJS
npm
onboarding
OpenSea
OPM
openUPM
openupm-cli
OnDestroy
OpenUPM
prebuilt
preconfigured
Expand All @@ -210,12 +228,16 @@ Rinkeby
rpc
RPC
RPCs
Reown
reown
SampleLoginMetamask
SampleMain
scalable
scrollable
SampleScene
scriptable
Scriptable
ScriptableObject
SDK
SDK.
SDK's
Expand All @@ -224,6 +246,7 @@ send-contract-through-webgl
send-transaction-through-webgl
sepolia
Sepolia
Sepolia's
sha3
SHA3
sign-through-webgl
Expand Down Expand Up @@ -261,6 +284,7 @@ TypeError
UI
Unity3D
uncomment
unsubscription
Uncomment
UnityEnvironment
UNPKG
Expand Down Expand Up @@ -324,12 +348,16 @@ Web3AuthSigner
Web3Builder
WebGLWallet
WebPageWallet
WebSocket
WebSockets
WebAssembly
xdai
XDai
YourGame
Zenject
zkDungeon
localhost
Localhost
localhost:8000
https
Brotli
Expand Down
15 changes: 14 additions & 1 deletion docs/1_chainsafe-gaming.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,20 @@ Out-of-the-box, Web3.unity comes with Unity sample scripts, scenes, prefabs & to

## Ready To Get Started?

#### Current SDK Builds (v2.x)
#### Current SDK Builds (v3.x)

In the latest 3.0 we've significantly reduced the effort for developers to interact with the blockchain. Once you have the core package installed you can just drag and drop the Web3Unity prefab to the scene:

```csharp
public class ExampleClass : MonoBehaviour
{
public async void Start()
{
await Web3Unity.Instance.Initialize(false);
await Web3Unity.Web3.Erc20.BalanceOf("0xd25b827D92b0fd656A1c829933e9b0b836d5C3e2");
}
}
```

[Click here](https://docs.gaming.chainsafe.io/current/getting-started) to open documentation for the latest version of web3.unity.

Expand Down
151 changes: 147 additions & 4 deletions docs/nft_marketplace/2_tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,152 @@ Once you have created a marketplace, its time to list some NFTs for sale in the
![](./assets/list_nft.gif)



## 4. Launch Your Marketplace

Once you have listed NFTs for your marketplace, you can access your marketplace items via RESTful set of APIs provided by the ChainSafe.
## 4. Use marketplace inside of your Unity game
Add the Chainsafe marketplace package as a git package:
`https://github.com/ChainSafe/web3.unity.git?path=/Packages/io.chainsafe.web3-unity.marketplace`
Add Marketplace Service Adapter to the Web3Unity prefab

![](./assets/marketplace_sample.png)

Fill out the necessary details


![](./assets/marketplace_overview.png)


- Marketplace ID: Labeled as ID on the page of your marketplace.
- Marketplace contract address: Labeled as Address on the page of your marketplace.
- Project ID override: Override this value if you want to use a project ID that is different from the one that you have in your Chainsafe SDK settings.
- Marketplace ABI override: Override this if you have created a custom version of our marketplace smart contract.
- Endpoint override: Override this if you are hosting marketplace somewhere else other than on the Chainsafes dashboard.

Once you fill out all the details you can list the items from the marketplace by simply calling

```csharp
var marketplacePage = await Web3Unity.Web3.Marketplace().LoadPage();
```
This will retrieve you a marketplace page, and not all the items that you have listed, because marketplace supports pagination, so you can add pagination support on your Unity client as well.
The basic sample can be found in the Samples section of the Marketplace package, but for the sake of simplicity I'll add the listing code snippet in here.
```csharp
namespace ChainSafe.Gaming.Marketplace.Samples
{
public class MarketplaceSample : MonoBehaviour
{
[SerializeField] private Transform parentForItems;
[SerializeField] private UI_MarketplaceItem marketplaceItem;
[SerializeField] private Button nextPageButton;

private MarketplacePage _currentPage;
private async void Start()
{
//Always make sure to initialize the Web3Unity instance first.
await Web3Unity.Instance.Initialize(false);
try
{
LoadingOverlay.ShowLoadingOverlay();
//This gets all items from the marketplace
//LoadPage has a lot of parameters that you can fill out in order to filter out the results.
_currentPage = await Web3Unity.Web3.Marketplace().LoadPage();

nextPageButton.interactable = !string.IsNullOrEmpty(_currentPage.Cursor);

await DisplayItems();
}
catch (Exception e)
{
Debug.LogError("Caught an exception whilst loading the marketplace page " + e.Message);
}
finally
{
LoadingOverlay.HideLoadingOverlay();
}
}

private async Task DisplayItems()
{
for (int i = parentForItems.childCount - 1; i >= 0; i--)
{
Destroy(parentForItems.GetChild(i).gameObject);
}
//_currentPage.Items holds the reference to all the items fetched from the marketplace
foreach (var pageItem in _currentPage.Items)
{
var item = Instantiate(marketplaceItem, parentForItems);
await item.Initialize(pageItem);
}
}
}
}


//Monobehaviour that handles the display of the marketplace items.
public class UI_MarketplaceItem : MonoBehaviour
{
[SerializeField] private Image marketplaceItemImage;
[SerializeField] private TMP_Text type, itemId, itemPrice, itemStatus;
[SerializeField] private Button button;

private MarketplaceItem _marketplaceItemModel;

private static Dictionary<string, Sprite> _spritesDict = new();

public async Task Initialize(MarketplaceItem model)
{
_marketplaceItemModel = model;
button.interactable = model.Status == MarketplaceItemStatus.Listed;
itemStatus.text = model.Status == MarketplaceItemStatus.Listed ? "Purchase" : model.Status.ToString();
marketplaceItemImage.sprite = await GetSprite(model);
type.text = model.Token.Type;
itemId.text = "ID " + model.Token.Id;
itemPrice.text =
((decimal)BigInteger.Parse(model.Price) / (decimal)BigInteger.Pow(10, 18)).ToString("0.############",
CultureInfo.InvariantCulture) + Web3Unity.Web3.ChainConfig.Symbol;
button.onClick.AddListener(Purchase);
}

private async Task<Sprite> GetSprite(MarketplaceItem model)
{
Sprite sprite = null;
string imageUrl = (string)model.Token.Metadata["image"];
//Caching data for faster retreival of the sprites.
if (_spritesDict.TryGetValue(imageUrl, out sprite)) return sprite;

var unityWebRequest = UnityWebRequestTexture.GetTexture(imageUrl);
await unityWebRequest.SendWebRequest();
if (unityWebRequest.error != null)
{
Debug.LogError("There was an error getting the texture " + unityWebRequest.error);
return null;
}

var myTexture = ((DownloadHandlerTexture)unityWebRequest.downloadHandler).texture;

sprite = Sprite.Create(myTexture, new Rect(0, 0, myTexture.width, myTexture.height), Vector2.one * 0.5f);

return sprite;
}

private async void Purchase()
{
try
{
await Web3Unity.Web3.Marketplace().Purchase(_marketplaceItemModel.Id, _marketplaceItemModel.Price);
//After the purchase is sucsessfull, just make the button unresponsive and set the button indicator to Sold
button.interactable = false;
itemStatus.text = "Sold";
}
catch (ServiceNotBoundWeb3Exception<ISigner> _)
{
Debug.LogError("You wanted to purchase an item and you don't have a wallet. Please connect the wallet to make a purchase");
Web3Unity.ConnectModal.Open();
}
}
}

```

## 5. Use marketplace with the Rest API

If you prefer to access your items without our official Marketplace plugin, once you have listed NFTs for your marketplace, you can access your marketplace items via RESTful set of APIs provided by the ChainSafe.
Head over to the [Marketplace API Specification](./../marketplace-api/docs/marketplaceapi.mdx) to know more about how to interact with the marketplace items.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 0 additions & 34 deletions docs/v2.6/15_marketplace.md

This file was deleted.

8 changes: 8 additions & 0 deletions docs/v2.6/18_faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,11 @@ You need to add the web3 component into your react build manually. To do so:
\<script src="%PUBLIC\_URL%/YourGame/web3/index.js">\</script> \<script src="%PUBLIC\_URL%/YourGame/web3/lib/web3modal.js">\</script> \<script src="%PUBLIC\_URL%/YourGame/web3/lib/web3.min.js">\</script> \<script src="%PUBLIC\_URL%/YourGame/network.js">\</script>
```
This should solve your issue. Happy coding!

### I'm having `IndexOutOfRangeException` exception thrown when building to WebGL

```
IndexOutOfRangeException: Index was outside the bounds of the array.
```

When building to WebGL you could run into this issue on some Unity versions. To fix this, simply open your project's _Player Settings_ then navigate to _Resolution and Presentation_ and pick **Web3.Unity** under _WebGL Template_. Even if it was already selected your project should be able to build to WebGL now.
Loading
Loading