109 lines
3.9 KiB
Vue
109 lines
3.9 KiB
Vue
<template>
|
|
<div>
|
|
<button @click="mintToken">mint</button>
|
|
<button @click="mintToken2">mint2</button>
|
|
<button @click="sacrificeMeme">sacrifice Meme</button>
|
|
<button @click="approveMeme1">approve Meme1</button>
|
|
<button @click="tokenStore.approveToken(MemeBurnerJson, 10)">wallet approve</button>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup>
|
|
import { onMounted, ref } from "vue";
|
|
import Web3 from "web3";
|
|
import Meme1Json from "@/assets/contracts/Meme1.json";
|
|
import Meme2Json from "@/assets/contracts/Meme2.json";
|
|
import MemeBurnerJson from "@/assets/contracts/MemeBurner.json";
|
|
import MemeTokenJson from "@/assets/contracts/MemeToken.json";
|
|
import RewardLockerJson from "@/assets/contracts/RewardLocker.json";
|
|
import { useTokenStore } from "@/stores/tokens";
|
|
|
|
const tokenStore = useTokenStore();
|
|
|
|
console.log("Meme1Json", Meme1Json);
|
|
console.log("Meme2Json", Meme2Json);
|
|
console.log("MemeBurnerJson", MemeBurnerJson);
|
|
console.log("MemeTokenJson", MemeTokenJson);
|
|
console.log("RewardLockerJson", RewardLockerJson);
|
|
|
|
// let web3 = new Web3(
|
|
// "https://eth-goerli.g.alchemy.com/v2/0-W9tOm6v_QP1PfRV8RuBCpWr-qoEbkN"
|
|
// );
|
|
// console.log("balanceOf", balanceOf);
|
|
const web3 = ref(null);
|
|
const contractMeme2 = ref(null);
|
|
const contractMeme1 = ref(null);
|
|
const contractBurner = ref(null);
|
|
|
|
onMounted(async () => {
|
|
web3.value = new Web3(window.ethereum);
|
|
// const contract = new web3.value.eth.Contract(Meme1Json.abi, Meme1Json.contractAddress);
|
|
console.log("web3", web3.value);
|
|
const accounts = await web3.value.eth.getAccounts();
|
|
console.log("accounts", accounts);
|
|
web3.value.eth.Contract.defaultAccount = accounts[0];
|
|
|
|
contractMeme1.value = new web3.value.eth.Contract(Meme1Json.abi, Meme1Json.contractAddress);
|
|
contractMeme2.value = new web3.value.eth.Contract(Meme2Json.abi, Meme2Json.contractAddress);
|
|
contractBurner.value = new web3.value.eth.Contract(MemeBurnerJson.abi, MemeBurnerJson.contractAddress);
|
|
});
|
|
|
|
async function approveMeme1() {
|
|
var approve = await contractMeme1.value.methods
|
|
.approve(MemeBurnerJson.contractAddress, 10)
|
|
.send({ from: web3.value.eth.Contract.defaultAccount });
|
|
console.log("approve", approve);
|
|
}
|
|
|
|
// async function approveMeme2() {
|
|
// var approve = await contractMeme1.value.methods.approve(web3.value.eth.Contract.defaultAccount, 10).send({ from: web3.value.eth.Contract.defaultAccount })
|
|
// console.log("approve", approve);
|
|
// }
|
|
|
|
|
|
// change this value to make yourself rich quick
|
|
async function mintToken() {
|
|
try {
|
|
var mint = await contractMeme1.value.methods
|
|
.mint("100000000000000000000000")
|
|
.send({ from: web3.value.eth.Contract.defaultAccount });
|
|
console.log("mint", mint);
|
|
} catch (error) {
|
|
console.log(error);
|
|
}
|
|
// var balanceOf = await contract.methods.balanceOf("0x66422602B2f4885c57EE794174f98d9E4DDBBBC6").call();
|
|
// console.log("balanceOf", balanceOf);
|
|
// var totalSupply = await contract.methods.totalSupply().call();
|
|
// console.log("totalSupply", totalSupply);
|
|
}
|
|
|
|
async function mintToken2() {
|
|
try {
|
|
var mint = await contractMeme2.value.methods
|
|
.mint("100000000000000000000")
|
|
.send({ from: web3.value.eth.Contract.defaultAccount });
|
|
console.log("mint", mint);
|
|
} catch (error) {
|
|
console.log(error);
|
|
}
|
|
// var balanceOf = await contract.methods.balanceOf("0x66422602B2f4885c57EE794174f98d9E4DDBBBC6").call();
|
|
// console.log("balanceOf", balanceOf);
|
|
// var totalSupply = await contract.methods.totalSupply().call();
|
|
// console.log("totalSupply", totalSupply);
|
|
}
|
|
|
|
|
|
// 1 Meme will be sacrificed
|
|
async function sacrificeMeme() {
|
|
const allowance = await contractMeme1.value.methods
|
|
.allowance(web3.value.eth.Contract.defaultAccount, MemeBurnerJson.contractAddress)
|
|
.call();
|
|
console.log("allowance", allowance);
|
|
var reward = await contractBurner.value.methods
|
|
.sacrificeMeme(Meme1Json.contractAddress, "1000000000000000000")
|
|
.send({ from: web3.value.eth.Contract.defaultAccount });
|
|
console.log("reward", reward);
|
|
}
|
|
// console.log("balanceOf", contract.mint(10));
|
|
</script>
|