Skip to content

Commit

Permalink
Contract.ReadRaw
Browse files Browse the repository at this point in the history
for cases where higher level reflection isn't good enough
  • Loading branch information
0xFirekeeper committed Apr 5, 2024
1 parent 4ba7b15 commit af009f4
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Assets/Thirdweb/Core/Scripts/Contract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,22 @@ public async Task<T> Read<T>(string functionName, params object[] args)
return JsonConvert.DeserializeObject<T>(JsonConvert.SerializeObject(rawResults));
}

public async Task<T> ReadRaw<T>(string functionName, params object[] args)
where T : new()
{
if (Utils.IsWebGLBuild())
{
return await Bridge.InvokeRoute<T>(getRoute("call"), Utils.ToJsonStringArray(functionName, args));
}

if (this.ABI == null)
throw new UnityException("You must pass an ABI for native platform custom calls");

var contract = Utils.GetWeb3().Eth.GetContract(this.ABI, this.Address);
var function = contract.GetFunction(functionName);
return await function.CallDeserializingToObjectAsync<T>(args);
}

private T ConvertValue<T>(object value)
{
if (value is T result)
Expand Down

0 comments on commit af009f4

Please sign in to comment.