-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
59 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,6 @@ function getZombiesByOwner(owner: string) { | |
} | ||
) | ||
} | ||
</script> | ||
|
||
<template> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { expect, test } from 'vitest' | ||
import Web3Utils from '../utils/web3utils'; | ||
|
||
test('init without provider', () => { | ||
var web3: Web3Utils = new Web3Utils(undefined) | ||
expect(web3.ethInit()).toBe(false) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { MetaMaskInpageProvider } from "@metamask/providers"; | ||
import Web3 from 'web3' | ||
import { Contract } from 'web3' | ||
import cryptozombiesABI from '../abi/zombieownership.sol/ZombieOwnership.json'; | ||
|
||
class Web3Utils { | ||
|
||
private web3js!: Web3; | ||
private ethereum!: MetaMaskInpageProvider; | ||
private readonly cryptoZombiesContractAddress: string = "0x5FbDB2315678afecb367f032d93F642f64180aa3"; | ||
public account!: string; | ||
public cryptoZombiesContract!: Contract<any>; | ||
|
||
constructor(ethereum: MetaMaskInpageProvider | undefined) { | ||
if (ethereum) { | ||
this.ethereum = ethereum | ||
} | ||
else { | ||
console.log("no window.ethereum, install Metamask"); | ||
} | ||
} | ||
|
||
ethInit(): boolean { | ||
|
||
if (this.ethereum == undefined) return false; | ||
|
||
console.log("Init Web 3"); | ||
this.ethereum.request({ method: 'eth_requestAccounts' }); | ||
this.web3js = new Web3(this.ethereum); | ||
this.web3js.eth.getAccounts().then((accounts: string[]) => { | ||
this.account = accounts[0]; | ||
// console.log("account : " + account); | ||
}) | ||
this.cryptoZombiesContract = new this.web3js.eth.Contract(cryptozombiesABI.abi, this.cryptoZombiesContractAddress); | ||
|
||
return true; | ||
} | ||
|
||
} | ||
|
||
export default Web3Utils; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters