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

Refine ERC20, ERC721, ERC1155 utility classes #952

Merged
merged 21 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
991fde2
Removed static Erc20, Erc721, Erc1155 utility classes from package sc…
creeppak May 13, 2024
2081ede
Merge branch 'dev' into oleksandr/refine-erc-xx
juans-chainsafe May 13, 2024
4acdfc1
Added contract caching for Erc20/721/1155 services.
creeppak May 14, 2024
a04c45a
Updated Erc20/Erc721/Erc1155 usage samples
creeppak May 14, 2024
7912a16
Merge remote-tracking branch 'origin/oleksandr/refine-erc-xx' into ol…
creeppak May 14, 2024
01643bb
Removed Custom Token Balance sample button
creeppak May 14, 2024
f45bb56
Merge branch 'dev' into oleksandr/refine-erc-xx
juans-chainsafe May 17, 2024
4df3ff0
Merge branch 'dev' into oleksandr/refine-erc-xx
juans-chainsafe May 17, 2024
5223494
Merge branch 'dev' into oleksandr/refine-erc-xx
juans-chainsafe May 20, 2024
0c086a6
Erc1155 ImportTexture fix
creeppak May 21, 2024
01fe418
Merge branch 'dev' into oleksandr/refine-erc-xx
creeppak May 21, 2024
13c5703
Erc1155 ImportTexture fix
creeppak May 21, 2024
21f6561
Merge remote-tracking branch 'origin/oleksandr/refine-erc-xx' into ol…
May 21, 2024
7ff0d74
Merge branch 'dev' into oleksandr/refine-erc-xx
kantagara May 28, 2024
6c19bc0
Fixing merging error
kantagara May 28, 2024
1232215
Fixing compiler errors
kantagara May 28, 2024
aec9145
Proper contract addresses
kantagara May 28, 2024
b409cfa
Fixed issue with WebGL not recognizing embedded resources.
kantagara May 28, 2024
f3eb393
Removed Custom Token Balance
kantagara May 28, 2024
943c4e4
Merge remote-tracking branch 'origin/dev' into oleksandr/refine-erc-xx
kantagara May 29, 2024
ea6a821
Merge branch 'dev' into oleksandr/refine-erc-xx
kantagara May 29, 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
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private void ConfigureCommonServices(IWeb3ServiceCollection services)
* to see how it's used later on.
*/
services.ConfigureRegisteredContracts(contracts =>
contracts.RegisterContract("CsTestErc20", ABI.Erc20, Contracts.Erc20));
contracts.RegisterContract("CsTestErc20", ABI.Erc20, ChainSafeContracts.Erc20));

}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Scripts.EVM.Token
{
public class Contracts
public class ChainSafeContracts
{
public const string Erc20 = "0x358969310231363CBEcFEFe47323139569D8a88b";
public const string Erc721 = "0x4f75BB7bdd6f7A0fD32f1b3A94dfF409F5a3F1CC";
Expand Down
191 changes: 0 additions & 191 deletions Packages/io.chainsafe.web3-unity/Runtime/Scripts/EVM/Token/Erc1155.cs

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Scripts.EVM.Token
{
public class Erc1155Metadata
{
public string image { get; set; }
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System.Diagnostics.Contracts;
using System.Text;
using System.Threading.Tasks;
using ChainSafe.Gaming.Evm.Contracts.BuiltIn;
using ChainSafe.Gaming.Ipfs;
using ChainSafe.Gaming.Web3;
using UnityEngine;
using UnityEngine.Networking;

namespace Scripts.EVM.Token
{
public static class Erc1155UnityExtensions
{
public static async Task<Texture2D> ImportTexture(this Erc1155Contract contract, string tokenId)
{
// fetch uri from chain
var uri = await contract.GetUri(tokenId);

// fetch metadata from uri
var metaRequest = UnityWebRequest.Get(uri);

if (metaRequest.result != UnityWebRequest.Result.Success)
{
throw new Web3Exception($"Metadata request failure: {metaRequest.error}");
}

// prepare texture uri
var metadata = JsonUtility.FromJson<Erc1155Metadata>(Encoding.UTF8.GetString(metaRequest.downloadHandler.data));
var textureUri = IpfsHelper.RollupIpfsUri(metadata.image);

// fetch texture
var textureRequest = UnityWebRequestTexture.GetTexture(textureUri);
await textureRequest.SendWebRequest();

if (textureRequest.result != UnityWebRequest.Result.Success)
{
throw new Web3Exception($"Texture request failure: {metaRequest.error}");
}

var texture = ((DownloadHandlerTexture)textureRequest.downloadHandler).texture;

return texture;
}

public static Task<Texture2D> ImportTexture(this Erc1155Service service, string contractAddress, string tokenId)
{
return service.BuildContract(contractAddress).ImportTexture(tokenId);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading