From f87aac417d5b9c0e1811c30808afcfee28b359f0 Mon Sep 17 00:00:00 2001 From: kunal528 Date: Sat, 25 Mar 2023 17:20:09 +0530 Subject: [PATCH] mantle deployed contract interaction completed --- MetaMask/Samples/Main/Scripts/MetaMaskDemo.cs | 38 +++++-------------- Scenes/MainScene.unity | 2 +- Scripts/CounterController.cs | 4 +- Scripts/GetContract.cs | 8 ++-- Scripts/TransactionData.cs | 21 +++++----- 5 files changed, 27 insertions(+), 46 deletions(-) diff --git a/MetaMask/Samples/Main/Scripts/MetaMaskDemo.cs b/MetaMask/Samples/Main/Scripts/MetaMaskDemo.cs index 6dbd01d..346da2a 100644 --- a/MetaMask/Samples/Main/Scripts/MetaMaskDemo.cs +++ b/MetaMask/Samples/Main/Scripts/MetaMaskDemo.cs @@ -14,9 +14,7 @@ using Nethereum.ABI.Model; using System.Numerics; using Nethereum.Util; - - - +using System.Threading.Tasks; namespace MetaMask.Unity.Samples { @@ -87,15 +85,20 @@ public void TransactionResult(object sender, MetaMaskEthereumRequestResultEventA } /// Raised when the wallet is connected. - private void walletConnected(object sender, EventArgs e) + private async void walletConnected(object sender, EventArgs e) { onWalletConnected?.Invoke(this, EventArgs.Empty); + await Sign(); + Cursor.visible = false; + Cursor.lockState = CursorLockMode.Locked; SceneManager.LoadScene("MainScene"); } /// Raised when the wallet is disconnected. private void walletDisconnected(object sender, EventArgs e) { + Cursor.visible = true; + Cursor.lockState = CursorLockMode.None; SceneManager.LoadScene("MetaMaskMain"); onWalletDisconnected?.Invoke(this, EventArgs.Empty); } @@ -157,31 +160,8 @@ public async void SendTransaction() /// Signs a message with the user's private key. /// The message to sign. /// Thrown when the application isn't in foreground. - public async void Sign() + public async Task Sign() { - //var address = "0xD98d0F8d0493408e218533AeFBf73bEEA67052E8"; - //var abi = "[{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"num\",\"type\":\"uint256\"}],\"name\":\"store\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"retrieve\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"}]"; - //var web3 = new Web3("https://rpc-mumbai.maticvigil.com"); - - - /*var contract = new ContractBuilder(abi, address); - var functionAbi = contract.GetFunctionBuilder("store").CreateTransactionInput(MetaMaskUnity.Instance.Wallet.SelectedAddress, new object[] { "1" }); - Debug.Log(functionAbi.Data); - Debug.Log(functionAbi.From); - Debug.Log(functionAbi.To); - var transaction = new TransactionBuidler( - functionAbi.To, - functionAbi.From, - functionAbi.Data, - "0x0" - );*/ - //var callContract = web3.Eth.GetContract(abi, address); - //var function = callContract.GetFunction("retrieve"); - - - //string msgParams = "{\"domain\":{\"chainId\":80001,\"name\":\"Ether Mail\",\"verifyingContract\":\"0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC\",\"version\":\"1\"},\"message\":{\"contents\":\"Hello, Bob!\",\"from\":{\"name\":\"Cow\",\"wallets\":[\"0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826\",\"0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF\"]},\"to\":[{\"name\":\"Bob\",\"wallets\":[\"0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB\",\"0xB0BdaBea57B0BDABeA57b0bdABEA57b0BDabEa57\",\"0xB0B0b0b0b0b0B000000000000000000000000000\"]}]},\"primaryType\":\"Mail\",\"types\":{\"EIP712Domain\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"version\",\"type\":\"string\"},{\"name\":\"chainId\",\"type\":\"uint256\"},{\"name\":\"verifyingContract\",\"type\":\"address\"}],\"Group\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"members\",\"type\":\"Person[]\"}],\"Mail\":[{\"name\":\"from\",\"type\":\"Person\"},{\"name\":\"to\",\"type\":\"Person[]\"},{\"name\":\"contents\",\"type\":\"string\"}],\"Person\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"wallets\",\"type\":\"address[]\"}]}}"; - //string from = MetaMaskUnity.Instance.Wallet.SelectedAddress; - //string msg = "{\"chainId\":\"0x13881\"}"; AddEthereumChainParameter addEthereumChainParameter = new AddEthereumChainParameter(); var paramsArray = new AddEthereumChainParameter[] { addEthereumChainParameter }; @@ -193,7 +173,7 @@ public async void Sign() }; onTransactionSent?.Invoke(this, EventArgs.Empty); await MetaMaskUnity.Instance.Wallet.Request(request); - + } public async void GetNFT(string id) diff --git a/Scenes/MainScene.unity b/Scenes/MainScene.unity index 0c32c37..277f90c 100644 --- a/Scenes/MainScene.unity +++ b/Scenes/MainScene.unity @@ -29687,7 +29687,7 @@ MonoBehaviour: m_OnCullStateChanged: m_PersistentCalls: m_Calls: [] - m_text: 'Min Amount: 10 MATIC' + m_text: 'Min Amount:' m_isRightToLeft: 0 m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} diff --git a/Scripts/CounterController.cs b/Scripts/CounterController.cs index 54a2d36..2f9dfa2 100644 --- a/Scripts/CounterController.cs +++ b/Scripts/CounterController.cs @@ -44,7 +44,7 @@ public void ChangeTime(string time, int id) { public void SetTimer(string value) { text.text = "Time Remaining: " + value; - amount.GetComponent().text = "Min Bid: " + MetaState.nft.min_bid + "MATIC"; + amount.GetComponent().text = "Min Bid: " + MetaState.nft.min_bid + "BIT"; bidder.GetComponent().text = "Highest Bidder: " + MetaState.nft.highest_bidder; System.DateTime epochStart = new System.DateTime(1970, 1, 1, 0, 0, 0, System.DateTimeKind.Utc); epochStart = epochStart.ToLocalTime(); @@ -76,7 +76,7 @@ public void OnCompleted() { { bidder.GetComponent().text = "Owner: " + MetaState.nft.owner; } - amount.GetComponent().text = "Sold at: " + MetaState.nft.min_bid + "MATIC"; + amount.GetComponent().text = "Sold at: " + MetaState.nft.min_bid + "BIT"; if (Int64.Parse(MetaState.nft.end_timestamp) < cur_time && MetaState.nft.owner == user && MetaState.nft.highest_bidder == user) { diff --git a/Scripts/GetContract.cs b/Scripts/GetContract.cs index 42ef8fa..be7f486 100644 --- a/Scripts/GetContract.cs +++ b/Scripts/GetContract.cs @@ -22,13 +22,13 @@ namespace IndiCultre public class IndiCultreConsole { - public string ADDRESS = "0x9BBf0A372f3C0BF060C215a8Ab2b6E349341cff8"; + public string ADDRESS = "0xDD93309A2090488ba88eadaB6670ED50d69d9CD9"; public string ABI = "[{\"inputs\":[{\"internalType\":\"uint32\",\"name\":\"tokenId\",\"type\":\"uint32\"}],\"name\":\"bid\",\"outputs\":[],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint32\",\"name\":\"tokenId\",\"type\":\"uint32\"}],\"name\":\"collect\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"sec\",\"type\":\"uint256\"}],\"name\":\"setDuration\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_nftAddress\",\"type\":\"address\"}],\"name\":\"setNFTContract\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint32\",\"name\":\"tokenId\",\"type\":\"uint32\"}],\"name\":\"startAuction\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"addressList\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"auctions\",\"outputs\":[{\"internalType\":\"uint32\",\"name\":\"tokenId\",\"type\":\"uint32\"},{\"internalType\":\"address\",\"name\":\"seller\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"bidder\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"bidAmount\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"endTimestamp\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"artist\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"name\":\"balances\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"MINIMUM_BIDDING_PRICE\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"}]"; - public string RPC_URL = "https://rpc-mumbai.maticvigil.com"; + public string RPC_URL = "https://rpc.testnet.mantle.xyz/"; public async Task GetById(string id) { @@ -307,11 +307,11 @@ public class IndiCultureNFTConsole { - public string ADDRESS = "0x2d6A12e0Cd3F9e399C06b862507674781dA438ea"; + public string ADDRESS = "0xd1f9caFdd4e160686C3A9545e8CF918d1a55cA7E"; public string ABI = "[{\"inputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"approved\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"Approval\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"operator\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"bool\",\"name\":\"approved\",\"type\":\"bool\"}],\"name\":\"ApprovalForAll\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"Transfer\",\"type\":\"event\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"approve\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"}],\"name\":\"balanceOf\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"marketplace\",\"type\":\"address\"}],\"name\":\"changeMarketplace\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"getApproved\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"getLatestTokenId\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"operator\",\"type\":\"address\"}],\"name\":\"isApprovedForAll\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"tokenURI\",\"type\":\"string\"}],\"name\":\"mint\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"name\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"ownerOf\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"safeTransferFrom\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"},{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"safeTransferFrom\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"operator\",\"type\":\"address\"},{\"internalType\":\"bool\",\"name\":\"approved\",\"type\":\"bool\"}],\"name\":\"setApprovalForAll\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes4\",\"name\":\"interfaceId\",\"type\":\"bytes4\"}],\"name\":\"supportsInterface\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"symbol\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"tokenURI\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"transferFrom\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]"; - public string RPC_URL = "https://rpc-mumbai.maticvigil.com"; + public string RPC_URL = "https://rpc.testnet.mantle.xyz/"; public async void Approve(string tokenId, string account) { diff --git a/Scripts/TransactionData.cs b/Scripts/TransactionData.cs index 34ee10f..330bdcb 100644 --- a/Scripts/TransactionData.cs +++ b/Scripts/TransactionData.cs @@ -1,4 +1,5 @@ - +using Nethereum.Hex.HexTypes; +using System.Numerics; class TransactionData { @@ -18,25 +19,25 @@ public TransactionData(string to, string from, string data, string value) { class AddEthereumChainParameter { - public string chainId = "0x13881"; // A 0x-prefixed hexadecimal string - public string chainName = "Mumbai"; + public string chainId = new HexBigInteger(new BigInteger(5001)).HexValue; // A 0x-prefixed hexadecimal string + public string chainName = "Mantle Testnet"; public NativeCurrency nativeCurrency = new NativeCurrency(); - public string[] rpcUrls = new string[] { "https://rpc-mumbai.maticvigil.com" }; - public string[] blockExplorerUrls = new string[] { "https://mumbai.polygonscan.com/" }; + public string[] rpcUrls = new string[] { "https://rpc.testnet.mantle.xyz/" }; + public string[] blockExplorerUrls = new string[] { "https://explorer.testnet.mantle.xyz/" }; } [System.Serializable] class NativeCurrency { - string name; - string symbol; - int decimals = 18; + public string name; + public string symbol; + public int decimals = 18; public NativeCurrency() { - name = "MATIC"; - symbol = "MATIC"; + name = "BIT"; + symbol = "BIT"; } }