Skip to content

Commit 190ce13

Browse files
Fix custom contract Read/Write for webGL (#58)
1 parent 6850db2 commit 190ce13

File tree

1 file changed

+3
-19
lines changed

1 file changed

+3
-19
lines changed

Assets/Thirdweb/Core/Scripts/Contract.cs

+3-19
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
using System;
2-
using System.Collections.Generic;
31
using System.Threading.Tasks;
42
using System.Numerics;
53
using UnityEngine;
6-
using UnityEngine.Networking;
7-
using Newtonsoft.Json;
84
using Nethereum.Hex.HexTypes;
95

106
namespace Thirdweb
@@ -48,8 +44,7 @@ public class Contract : Routable
4844
/// </summary>
4945
public Events events;
5046

51-
public Contract(string chain, string address, string abi = null)
52-
: base(abi != null ? $"{address}{Routable.subSeparator}{abi}" : address)
47+
public Contract(string chain, string address, string abi = null) : base(abi != null ? $"{address}{Routable.subSeparator}{abi}" : address)
5348
{
5449
this.chain = chain;
5550
this.address = address;
@@ -88,10 +83,7 @@ public async Task<T> Read<T>(string functionName, params object[] args)
8883
{
8984
if (Utils.IsWebGLBuild())
9085
{
91-
string[] argsEncoded = new string[args.Length + 1];
92-
argsEncoded[0] = functionName;
93-
Utils.ToJsonStringArray(args).CopyTo(argsEncoded, 1);
94-
return await Bridge.InvokeRoute<T>(getRoute("call"), argsEncoded);
86+
return await Bridge.InvokeRoute<T>(getRoute("call"), Utils.ToJsonStringArray(functionName, args));
9587
}
9688
else
9789
{
@@ -127,15 +119,7 @@ public async Task<TransactionResult> Write(string functionName, TransactionReque
127119
if (Utils.IsWebGLBuild())
128120
{
129121
args = args ?? new object[0];
130-
var hasOverrides = transactionOverrides != null;
131-
string[] argsEncoded = new string[args.Length + (hasOverrides ? 2 : 1)];
132-
argsEncoded[0] = functionName;
133-
Utils.ToJsonStringArray(args).CopyTo(argsEncoded, 1);
134-
if (hasOverrides)
135-
{
136-
argsEncoded[argsEncoded.Length - 1] = Utils.ToJson(transactionOverrides);
137-
}
138-
return await Bridge.InvokeRoute<TransactionResult>(getRoute("call"), argsEncoded);
122+
return await Bridge.InvokeRoute<TransactionResult>(getRoute("call"), Utils.ToJsonStringArray(functionName, args, transactionOverrides));
139123
}
140124
else
141125
{

0 commit comments

Comments
 (0)