Skip to content

Latest commit

 

History

History
87 lines (61 loc) · 2.18 KB

File metadata and controls

87 lines (61 loc) · 2.18 KB
description
A standard interface for EVM methods

EVM

This section contains the different types of EVM methods that can be used in the Unity SDK. For additional operations and methods please refer to the ChainSafe Documentation.

Player Account

PlayerPrefs.GetString("Account") is the user's wallet account accessed after the LoginScene.

string account = PlayerPrefs.GetString("Account");
print(account);

{% hint style="info" %} Important: If you run your script from the editor, you will have to hardcode the account string (e.g. "0x6e...") {% endhint %}

Block number

Get the current latest block number

string chain = "cronos";
string network = "mainnet"; // mainnet or testnet

int blockNumber = await EVM.BlockNumber(chain, network);
print(blockNumber); Some code

Balance Of

Get the balance of the native blockchain

string chain = "cronos";
string network = "mainnet"; // mainnet or testnet
string account = "WALLET_ADDRESS";

string balance = await EVM.BalanceOf(chain, network, account, rpc);
print(balance);

Verify

Verify a signed message.

string message = "YOUR_MESSAGE";
string signature = "YOUR_SIGNATURE";

string address = await EVM.Verify(message, signature);
print(address);

Nonce

Print Nonce.

string chain = "cronos";
string network = "mainnet"; // mainnet or testnet
string account = "WALLET_ADDRESS";
string rpc = "https://evm-dev.cronos.org";

string nonce = await EVM.Nonce(chain, network, account, rpc);
print(nonce);

Convert WEI to CRO and CRO to WEI

Converts WEI values

float cro = float.Parse("0.1");
float decimals = 1000000000000000000; // 18 decimals
float wei = cro * decimals;
print(Convert.ToDecimal(wei).ToString());

float wei = float.Parse("10123755");
float decimals = 1000000000000000000; // 18 decimals
float cro = wei / decimals;
print(Convert.ToDecimal(cro).ToString());