Skip to content

Commit

Permalink
Merge pull request #2 from HyperPlay-Gaming/callContract
Browse files Browse the repository at this point in the history
Call contract
  • Loading branch information
leon-do authored Mar 16, 2023
2 parents 6a76e40 + de7b5ab commit d25cb52
Show file tree
Hide file tree
Showing 403 changed files with 18 additions and 23,692 deletions.
23 changes: 18 additions & 5 deletions Assets/HYPERPLAY/SyncBalance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,8 @@ public class SyncBalance : MonoBehaviour

async public void OnSyncBalance()
{
// https://docs.gaming.chainsafe.io/erc20#balance-of_3
string chain = "ethereum";
string network = "goerli";
string contract = "0xDD6ff2bA7fD02D19e8e4e1d99b65802eD9705437";
string account = await GetAccount();
BigInteger balanceOf = await ERC20.BalanceOf(chain, network, contract, account);
BigInteger balanceOf = await GetERC20Balance(account);

// display on button
PlayerBalance.text = "Sync Balance: " + balanceOf.ToString();
Expand All @@ -34,6 +30,23 @@ async public void OnSyncBalance()
}
}

async private static Task<BigInteger> GetERC20Balance(string _account) {
string jsonString = "{ \"contractAddress\": \"0xDD6ff2bA7fD02D19e8e4e1d99b65802eD9705437\", \"functionName\": \"balanceOf\", \"abi\": [{ \"inputs\": [{ \"internalType\": \"address\", \"name\": \"account\", \"type\": \"address\" }], \"name\": \"balanceOf\", \"outputs\": [{ \"internalType\": \"uint256\", \"name\": \"\", \"type\": \"uint256\" }], \"stateMutability\": \"view\", \"type\": \"function\" }], \"params\": [\"" + _account + "\"], \"chain\": { \"chainId\": \"5\" } }";
byte[] jsonBytes = System.Text.Encoding.UTF8.GetBytes(jsonString);

UnityWebRequest request = new UnityWebRequest("localhost:9680/callContract", "POST");
request.uploadHandler = new UploadHandlerRaw(jsonBytes);
request.downloadHandler = new DownloadHandlerBuffer();
request.SetRequestHeader("Content-Type", "application/json");

await request.SendWebRequest();
string response = request.downloadHandler.text; // "1"
print(response);
// convert to BigInteger
BigInteger balanceOf = BigInteger.Parse(response);
return balanceOf;
}

async private static Task<string> GetAccount() {
string jsonString = "{\"request\":{\"method\":\"eth_accounts\"},\"chain\":{\"chainId\":\"5\"}}";
byte[] jsonBytes = System.Text.Encoding.UTF8.GetBytes(jsonString);
Expand Down
8 changes: 0 additions & 8 deletions Assets/Plugins/Jint.meta

This file was deleted.

Binary file removed Assets/Plugins/Jint/Jint.dll
Binary file not shown.
33 changes: 0 additions & 33 deletions Assets/Plugins/Jint/Jint.dll.meta

This file was deleted.

8 changes: 0 additions & 8 deletions Assets/Plugins/Nethereum.meta

This file was deleted.

54 changes: 0 additions & 54 deletions Assets/Plugins/Nethereum/AddressExtensions.cs

This file was deleted.

11 changes: 0 additions & 11 deletions Assets/Plugins/Nethereum/AddressExtensions.cs.meta

This file was deleted.

134 changes: 0 additions & 134 deletions Assets/Plugins/Nethereum/AddressUtil.cs

This file was deleted.

11 changes: 0 additions & 11 deletions Assets/Plugins/Nethereum/AddressUtil.cs.meta

This file was deleted.

65 changes: 0 additions & 65 deletions Assets/Plugins/Nethereum/ByteUtil.cs

This file was deleted.

11 changes: 0 additions & 11 deletions Assets/Plugins/Nethereum/ByteUtil.cs.meta

This file was deleted.

Loading

0 comments on commit d25cb52

Please sign in to comment.