Custom Interactions

Call Custom Blockchains

Connect to any EVM compatible blockchain by providing an RPC. All methods have an optional field to add an RPC URL.
string chain = "rootstock";
string network = "testnet";
string account = "0xdD4c825203f97984e7867F11eeCc813A036089D1";
string rpc = "https://public-node.testnet.rsk.co";
string balance = await EVM.BalanceOf(chain, network, account, rpc);
print(balance);

Call Custom Contracts

Call will execute a smart contract method without altering the smart contract state.

Solidity Contract Example

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract AddTotal {
uint256 public myTotal = 0;
function addTotal(uint8 _myArg) public {
myTotal = myTotal + _myArg;
}
}

Reading a value from a solidity contract

// set chain
string chain = "ethereum";
// set network
string network = "goerli";
// abi in json format
string abi = "[ { \"inputs\": [ { \"internalType\": \"uint8\", \"name\": \"_myArg\", \"type\": \"uint8\" } ], \"name\": \"addTotal\", \"outputs\": [], \"stateMutability\": \"nonpayable\", \"type\": \"function\" }, { \"inputs\": [], \"name\": \"myTotal\", \"outputs\": [ { \"internalType\": \"uint256\", \"name\": \"\", \"type\": \"uint256\" } ], \"stateMutability\": \"view\", \"type\": \"function\" } ]";
// address of contract
string contract = "0x741C3F3146304Aaf5200317cbEc0265aB728FE07";
// array of arguments for contract
string args = "[]";
// connects to user's browser wallet to call a transaction
string response = await EVM.Call(chain, network, contract, abi, method, args);
// display response in game
print(response);

Writing a value to a solidity contract (WebGL Builds)

// set chain
string chain = "ethereum";
// set network
string network = "goerli";
// abi in json format
string abi = "[ { \"inputs\": [ { \"internalType\": \"uint8\", \"name\": \"_myArg\", \"type\": \"uint8\" } ], \"name\": \"addTotal\", \"outputs\": [], \"stateMutability\": \"nonpayable\", \"type\": \"function\" }, { \"inputs\": [], \"name\": \"myTotal\", \"outputs\": [ { \"internalType\": \"uint256\", \"name\": \"\", \"type\": \"uint256\" } ], \"stateMutability\": \"view\", \"type\": \"function\" } ]";
// address of contract
string contract = "0x741C3F3146304Aaf5200317cbEc0265aB728FE07";
// method you want to write to
string method = "addTotal";
// amount you want to change, in this case we are adding 1 to "addTotal"
string amount = "1";
// array of arguments for contract
string[] obj = {amount};
string args = JsonConvert.SerializeObject(obj);
// connects to user's browser wallet to call a transaction
string response = await Web3GL.SendContract(method, abi, contract, args, "0", "", "");
// display response in game
print(response);

Writing a value to a solidity contract (Web Wallet Builds)

// set chain
string chain = "ethereum";
// set network
string network = "goerli";
// set chainID, here we use the networkID for goerli
string chainId = "5";
// abi in json format
string abi = "[ { \"inputs\": [ { \"internalType\": \"uint8\", \"name\": \"_myArg\", \"type\": \"uint8\" } ], \"name\": \"addTotal\", \"outputs\": [], \"stateMutability\": \"nonpayable\", \"type\": \"function\" }, { \"inputs\": [], \"name\": \"myTotal\", \"outputs\": [ { \"internalType\": \"uint256\", \"name\": \"\", \"type\": \"uint256\" } ], \"stateMutability\": \"view\", \"type\": \"function\" } ]";
// address of contract
string contract = "0x741C3F3146304Aaf5200317cbEc0265aB728FE07";
// method you want to write to
string method = "addTotal";
// amount you want to change, in this case we are adding 1 to "addTotal"
string amount = "1";
// array of arguments for contract
string[] obj = {amount};
string args = JsonConvert.SerializeObject(obj);
// create data for contract interaction
string data = await EVM.CreateContractData(abi, method, args);
// send transaction
string response = await Web3Wallet.SendTransaction(chainId, contract, "0", data, "", "");
// display response in game
print(response);
Last modified 3h ago
Copy link
On this page
Call Custom Blockchains
Call Custom Contracts
Solidity Contract Example
Reading a value from a solidity contract
Writing a value to a solidity contract (WebGL Builds)
Writing a value to a solidity contract (Web Wallet Builds)