import {ethers} from "ethers";
import Legacy from "../contractABI.json";


var provider;
var signer;
var contract;
var contractAddress = "0x1F4649C10854EB727369E746a5Bae73e8Dca6740";
var contractWithSigner;
var contractABI = Legacy.abi;

async function init(){
  var myProvider = new ethers.providers.Web3Provider(window.ethereum);
  await myProvider.send("eth_requestAccounts", []);
  var blockNumber = await myProvider.getBlockNumber();
  console.log("blockNumber: " + blockNumber);
  var mySigner = myProvider.getSigner();
  var myContract = new ethers.Contract(contractAddress, contractABI, myProvider);
  var myContractWithSigner = myContract.connect(mySigner);
  this.contractWithSigner = myContractWithSigner;
}

export default {
  init,
  provider,
  signer,
  contract,
  contractWithSigner
}
