Skip to content

Commit af009f4

Browse files
committed
Contract.ReadRaw
for cases where higher level reflection isn't good enough
1 parent 4ba7b15 commit af009f4

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Assets/Thirdweb/Core/Scripts/Contract.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,22 @@ public async Task<T> Read<T>(string functionName, params object[] args)
383383
return JsonConvert.DeserializeObject<T>(JsonConvert.SerializeObject(rawResults));
384384
}
385385

386+
public async Task<T> ReadRaw<T>(string functionName, params object[] args)
387+
where T : new()
388+
{
389+
if (Utils.IsWebGLBuild())
390+
{
391+
return await Bridge.InvokeRoute<T>(getRoute("call"), Utils.ToJsonStringArray(functionName, args));
392+
}
393+
394+
if (this.ABI == null)
395+
throw new UnityException("You must pass an ABI for native platform custom calls");
396+
397+
var contract = Utils.GetWeb3().Eth.GetContract(this.ABI, this.Address);
398+
var function = contract.GetFunction(functionName);
399+
return await function.CallDeserializingToObjectAsync<T>(args);
400+
}
401+
386402
private T ConvertValue<T>(object value)
387403
{
388404
if (value is T result)

0 commit comments

Comments
 (0)