web3.unity
web3.unity copied to clipboard
Evm.ContractSend doesn't execute the contract.
Describe the bug No error logs pop up but the Metamask prompt also doesn't show after trying Evm.ContractSend with the contract's buy method (see contract details listed below).
Steps Steps to reproduce the behavior:
- Install Chainsafe SDK version 2.5.5 #825 (recent commit last Feb 9) on Unity 2021.3.15f1.
- Configure server to ShimmerEVM Testnet 1073.
- Contract details:
Method: "buy"
Address: "0xa8C749092E6907079f23850073156d5e9F65B5f6" ABI: "[{"inputs":[{"internalType":"address","name":"_itemTokenAddress","type":"address"},{"internalType":"address","name":"_itemCoderAddress","type":"address"},{"internalType":"uint256","name":"_deckPrice","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"uint256","name":"deckCount","type":"uint256"}],"name":"InvalidDeckCount","type":"error"},{"inputs":[{"internalType":"uint256","name":"paymentAmount","type":"uint256"}],"name":"InvalidPaymentAmount","type":"error"},{"inputs":[{"internalType":"uint256","name":"rarity","type":"uint256"}],"name":"InvalidRarityLevel","type":"error"},{"inputs":[{"internalType":"uint256","name":"decksLeft","type":"uint256"}],"name":"NotEnoughDecksLeft","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"OwnableInvalidOwner","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"OwnableUnauthorizedAccount","type":"error"},{"inputs":[],"name":"ReentrancyGuardReentrantCall","type":"error"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"RoleNotGranted","type":"error"},{"inputs":[],"name":"SaleNotActive","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"newPrice","type":"uint256"}],"name":"DeckPriceChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"saleActive","type":"bool"}],"name":"SaleStatusChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"buyer","type":"address"},{"components":[{"internalType":"uint256[]","name":"cardIds","type":"uint256[]"},{"internalType":"bool","name":"shinyCard","type":"bool"},{"internalType":"uint8","name":"shinyCardIndex","type":"uint8"},{"internalType":"uint8","name":"totalCards","type":"uint8"}],"indexed":false,"internalType":"structStarterDeckMarketplace.CardDeck[]","name":"decks","type":"tuple[]"}],"name":"StarterDecksPurchased","type":"event"},{"inputs":[],"name":"DECKS_BUY_LIMIT","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PERCENTAGE_BASIS_POINTS","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"SHINY_CHANCE","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint8","name":"_count","type":"uint8"}],"name":"buy","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"deckPrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decksMax","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decksSold","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_rarityLevel","type":"uint256"}],"name":"getCardWeights","outputs":[{"components":[{"internalType":"uint16","name":"cardId","type":"uint16"},{"internalType":"uint256","name":"weight","type":"uint256"}],"internalType":"structStarterDeckMarketplace.CardWeight[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getDecksLeft","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_rarityLevel","type":"uint256"}],"name":"getRarityWeight","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getRarityWeights","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"saleActive","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_newPrice","type":"uint256"}],"name":"setDeckPrice","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_newMaxStarterDecks","type":"uint256"}],"name":"setDecksMax","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"_newSaleStatus","type":"bool"}],"name":"setSaleStatus","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_withdrawAddress","type":"address"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"}]" - Build with Metamask Template.
- Start the ContractSend method.
Expected behavior The Metamask prompt should show up and execute the contract.
Console errors None show up.
Reproducible Code Snippet (if applicable):
csharp
string abi = [insert abi];
string address = [insert address];
string method = "buy";
string price = "100000000000000000000"; BigInteger bigIntPrice = BigInteger.Parse(price);
var response = Evm.ContractSend(Web3Accessor.Web3, method, abi, address, new object[]{ 1 }, new HexBigInteger(bigIntPrice));
Desktop (please complete the following information):
- Chainsafe SDK version: 2.5.5 #825
- Unity Version: 2021.3.15f1
- Operating System: Windows 11
- Browsers Tested: Brave
Additional context Got the package from the most recent commit since 2.5.5 last Feb 9. Saw the additional fix for adding in a value parameter for Evm.ContractSend so I decided on it just for testing. Installed on 2021.3.15f1 and using the WebGL-Metamask template.
Tried the sample scene with the Sepolia sample calls for a sanity check and the ContractSend method worked. Only displayed weird behavior with these put in. I was also able to execute this same contract successfully in 2.1.0 using the Web3GL.SendContract method.
@Jlg-pluck - can you just open the metamask extension, maybe then the prompt will appear?
Tried and it didn't. I see it requesting and calling data in the background but nothing happens. Reading from the same contract work, it's just in writing values to this particular one. Maybe some syntax I'm missing out?
show me your solidity function and the way you're calling it c# side, it's probably a syntax or parameter issue.
Thanks for looking into this! Solidity can be viewed here https://explorer.evm.testnet.shimmer.network/address/0xa8C749092E6907079f23850073156d5e9F65B5f6?tab=contact_code.
The code I used is the one I put in above. If it helps for cross-checking, the working contract execution I did for 2.1.0 is this one below:
string[] obj = {"1"}; string args = JsonConvert.SerializeObject(obj); string value = "100000000000000000000"; var response = await Web3GL.SendContract(method, abi, address, args, value, gasLimit, gasPrice);
Please try this for me and let me know if you get any errors
using System;
using System.Numerics;
using ChainSafe.Gaming.UnityPackage;
using ChainSafe.Gaming.Web3;
using Nethereum.Hex.HexTypes;
using Scripts.EVM.Token;
using UnityEngine;
public class TestCall : MonoBehaviour
{
// Variables
private string abi =
"[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_itemTokenAddress\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"_itemCoderAddress\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"_deckPrice\",\"type\":\"uint256\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"deckCount\",\"type\":\"uint256\"}],\"name\":\"InvalidDeckCount\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"paymentAmount\",\"type\":\"uint256\"}],\"name\":\"InvalidPaymentAmount\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"rarity\",\"type\":\"uint256\"}],\"name\":\"InvalidRarityLevel\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"decksLeft\",\"type\":\"uint256\"}],\"name\":\"NotEnoughDecksLeft\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"}],\"name\":\"OwnableInvalidOwner\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"OwnableUnauthorizedAccount\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"ReentrancyGuardReentrantCall\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"role\",\"type\":\"bytes32\"}],\"name\":\"RoleNotGranted\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"SaleNotActive\",\"type\":\"error\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"newPrice\",\"type\":\"uint256\"}],\"name\":\"DeckPriceChanged\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"previousOwner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"OwnershipTransferred\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"bool\",\"name\":\"saleActive\",\"type\":\"bool\"}],\"name\":\"SaleStatusChanged\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"buyer\",\"type\":\"address\"},{\"components\":[{\"internalType\":\"uint256[]\",\"name\":\"cardIds\",\"type\":\"uint256[]\"},{\"internalType\":\"bool\",\"name\":\"shinyCard\",\"type\":\"bool\"},{\"internalType\":\"uint8\",\"name\":\"shinyCardIndex\",\"type\":\"uint8\"},{\"internalType\":\"uint8\",\"name\":\"totalCards\",\"type\":\"uint8\"}],\"indexed\":false,\"internalType\":\"structStarterDeckMarketplace.CardDeck[]\",\"name\":\"decks\",\"type\":\"tuple[]\"}],\"name\":\"StarterDecksPurchased\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"DECKS_BUY_LIMIT\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"PERCENTAGE_BASIS_POINTS\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"SHINY_CHANCE\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint8\",\"name\":\"_count\",\"type\":\"uint8\"}],\"name\":\"buy\",\"outputs\":[],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"deckPrice\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"decksMax\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"decksSold\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_rarityLevel\",\"type\":\"uint256\"}],\"name\":\"getCardWeights\",\"outputs\":[{\"components\":[{\"internalType\":\"uint16\",\"name\":\"cardId\",\"type\":\"uint16\"},{\"internalType\":\"uint256\",\"name\":\"weight\",\"type\":\"uint256\"}],\"internalType\":\"structStarterDeckMarketplace.CardWeight[]\",\"name\":\"\",\"type\":\"tuple[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"getDecksLeft\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_rarityLevel\",\"type\":\"uint256\"}],\"name\":\"getRarityWeight\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"getRarityWeights\",\"outputs\":[{\"internalType\":\"uint256[]\",\"name\":\"\",\"type\":\"uint256[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"owner\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"renounceOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"saleActive\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_newPrice\",\"type\":\"uint256\"}],\"name\":\"setDeckPrice\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_newMaxStarterDecks\",\"type\":\"uint256\"}],\"name\":\"setDecksMax\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bool\",\"name\":\"_newSaleStatus\",\"type\":\"bool\"}],\"name\":\"setSaleStatus\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"transferOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_withdrawAddress\",\"type\":\"address\"}],\"name\":\"withdraw\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]";
private string contractAddress = "0xa8C749092E6907079f23850073156d5e9F65B5f6";
private string method = "buy";
private int amountToBuy = 1;
private string price = "100000000000000000000";
// Function
public async void ContractSend()
{
try
{
object[] args =
{
amountToBuy
};
BigInteger bigIntPrice = BigInteger.Parse(price);
var amount = new HexBigInteger(bigIntPrice);
var data = await Evm.ContractSend(Web3Accessor.Web3, method, abi, contractAddress, args, amount);
var response = SampleOutputUtil.BuildOutputValue(data);
Debug.Log($"TX: {response}");
// You can make additional changes after this line
}
catch (Web3Exception e)
{
Console.WriteLine(e);
throw;
}
}
}
Sure! I used the script and this popped up.
Hmm, to me this looks like that code stripping is not set to minimal, can you check if it is?
Yep! Checked again and it's already set to Minimal.
Good day! I'd like to ask if there's any new progress for issue. We'd wanted to upgrade the full project to the latest version but with our contract interactions not fully working, it's been put on hold at the moment. If not, we can wait for the next stable release as long as we know the estimated timeline as well!
Hey , we did make some fixes around wallet connect, so can you please try out the latest commit? If it's not working then I can assure you that we will look at this issue starting end of march, and the stable release of the new Chainsafe SDK (2.6) will come out Mid-April.
This should be working now following the install settings in the blue box from the documentation here https://docs.gaming.chainsafe.io/current/getting-started Just make sure you're running the login screen firs to create a connection and then execute the script in the next scene.
Closing as updates have fixed this