Skip to main content

EVM API Unity

Before starting check the sdk docs

Setup Client

var client = new Seddona.GanacheClient();
// optionally use ganache: var client = new Seddona.Client();

Wallet API

Wallet.GetAddress

Get the current users selected address

string address = await client.Wallet.GetAddress();

Wallet.GetBalance

Get the native token balance

BigInteger balance = await client.Wallet.GetBalance();

Wallet.PersonalSign

signs the users key with "Ethereum Signed Message:" prefix for use in key authentication

string signature = await client.Wallet.PersonalSign("Example `personal_sign` message");

Wallet.TransactionCount

uint count = await client.Wallet.TransactionCount("Example `personal_sign` message");

Chain API

Chain.GetBlockNumber

Get the current block number

uint height = await client.Chain.GetBlockHeight();

Chain.GetLatestBlock

get a specific transaction

Block block = await client.Chain.GetLatestBlock();

Chain.GetLatestBlock

get a specific transaction

Block block = await client.Chain.GetBlockAtHeight(1);

Contract API

Contract.Deploy

Given a JSON output build from solidity deploy a contract

Contract contract = await Contract.Deploy(contract_json, client);

Instantiate Existing Contract

Configure an existing contract

string address = "0x0000000000000000000000000000000000000000";
string abi_json = @"[
{
\"name\": \"faucet\", \"outputs\": [], \"stateMutability\": \"nonpayable\", \"type\": \"function\",
\"inputs\": [{\"internalType\": \"address\",\"name\": \"addr\",\"type\": \"address\"}],
}
]";

Contract myContract = new Contract(address, abi_json, client);

contract.GetAddress

Get the address for a contract object

string address = await myContract.GetAddress();

contract.Call

Call contract functions

string txid = await myContract.Call("faucet", Abi.Token.IntoAddress("0xfC57cF2A89A15F6c423B276343bBB5103c2825DD"));
string txid = await myContract.Call("transferFrom", new [] {
Abi.Token.IntoAddress("0xfC57cF2A89A15F6c423B276343bBB5103c2825DD"),
Abi.Token.IntoAddress("0xEC68BcCc9b326F612384d64ffF9f4de0Bea9511e"),
Abi.Token.IntoAddress(0),
);

contract.Query

Query view functions on a contract

Token token = await myContract.Query("ownerOf", Abi.Token.IntoUint(0));

Token token = await myContract.Query("getOwnersTokens", Abi.Token.IntoAddress("0x0000000000000000000000000000000000"));
var owners = token.GetArray();
for (var i = 0; i < owners.Length; i++) {
var token = owners[i].GetUint();
}