统一代码
公共类 CustomCallExample:MonoBehaviour
{
异步无效开始()
{
// set chain: ethereum, moonbeam, polygon etc
string chain = "Localhost 8545";
// set network mainnet, testnet
string network = "testnet";
// smart contract method to call
string method = "getUserBalance";
// abi in json format
string abi = "[ { \"inputs\": [ { \"internalType\": \"address\", \"name\": \"_owner\", \"type\": \"address\" } ], \"name\": \"getUserBalance\", \"outputs\": [ { \"internalType\": \"uint256\", \"name\": \"\", \"type\": \"uint256\" } ], \"stateMutability\": \"view\", \"type\": \"function\" } ]";
//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 = "0x956FA7cbFb8db9077E950502231F6B50FCf70bCA";
// 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);
}
}
智能合约
contract NFTMarket {
function getUserBalance(address _owner) external view returns (uint) {
return address(_owner).balance;
}
我在 UNITY 中使用 ChainSafe SDK,想调用自定义智能合约交互。 但错误是
如何在统一的合约方法中将用户地址作为参数传递。 函数是 getUserBalance()。
我希望你能理解我的问题。