Skip to content

Commit

Permalink
mantle deployed contract interaction completed
Browse files Browse the repository at this point in the history
  • Loading branch information
kunal528 committed Mar 25, 2023
1 parent 75df425 commit f87aac4
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 46 deletions.
38 changes: 9 additions & 29 deletions MetaMask/Samples/Main/Scripts/MetaMaskDemo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
using Nethereum.ABI.Model;
using System.Numerics;
using Nethereum.Util;



using System.Threading.Tasks;

namespace MetaMask.Unity.Samples
{
Expand Down Expand Up @@ -87,15 +85,20 @@ public void TransactionResult(object sender, MetaMaskEthereumRequestResultEventA
}

/// <summary>Raised when the wallet is connected.</summary>
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");
}

/// <summary>Raised when the wallet is disconnected.</summary>
private void walletDisconnected(object sender, EventArgs e)
{
Cursor.visible = true;
Cursor.lockState = CursorLockMode.None;
SceneManager.LoadScene("MetaMaskMain");
onWalletDisconnected?.Invoke(this, EventArgs.Empty);
}
Expand Down Expand Up @@ -157,31 +160,8 @@ public async void SendTransaction()
/// <summary>Signs a message with the user's private key.</summary>
/// <param name="msgParams">The message to sign.</param>
/// <exception cref="InvalidOperationException">Thrown when the application isn't in foreground.</exception>
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 };
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Scenes/MainScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
4 changes: 2 additions & 2 deletions Scripts/CounterController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void ChangeTime(string time, int id) {

public void SetTimer(string value) {
text.text = "Time Remaining: " + value;
amount.GetComponent<TextMeshProUGUI>().text = "Min Bid: " + MetaState.nft.min_bid + "MATIC";
amount.GetComponent<TextMeshProUGUI>().text = "Min Bid: " + MetaState.nft.min_bid + "BIT";
bidder.GetComponent<TextMeshProUGUI>().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();
Expand Down Expand Up @@ -76,7 +76,7 @@ public void OnCompleted() {
{
bidder.GetComponent<TextMeshProUGUI>().text = "Owner: " + MetaState.nft.owner;
}
amount.GetComponent<TextMeshProUGUI>().text = "Sold at: " + MetaState.nft.min_bid + "MATIC";
amount.GetComponent<TextMeshProUGUI>().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)
{

Expand Down
8 changes: 4 additions & 4 deletions Scripts/GetContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AuctionsOutputDTO> GetById(string id)
{
Expand Down Expand Up @@ -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)
{

Expand Down
21 changes: 11 additions & 10 deletions Scripts/TransactionData.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

using Nethereum.Hex.HexTypes;
using System.Numerics;

class TransactionData
{
Expand All @@ -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";
}
}

Expand Down

0 comments on commit f87aac4

Please sign in to comment.