Add initial alchemy structure code
This commit is contained in:
parent
6a4884aec9
commit
aedd4bc532
@ -1 +1,3 @@
|
|||||||
VITE_API_URL=http://localhost:8000/
|
VITE_API_URL=http://localhost:8000/
|
||||||
|
VITE_GOERLI_API_KEY={GOERLI_API_KEY_ALCHEMY}
|
||||||
|
VITE_MUMBAI_API_KEY={MUMBAI_API_KEY_ALCHEMY}
|
10468
package-lock.json
generated
Normal file
10468
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -14,6 +14,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@headlessui/vue": "^1.7.3",
|
"@headlessui/vue": "^1.7.3",
|
||||||
"@heroicons/vue": "^2.0.12",
|
"@heroicons/vue": "^2.0.12",
|
||||||
|
"alchemy-sdk": "^2.3.0",
|
||||||
"axios": "^1.2.1",
|
"axios": "^1.2.1",
|
||||||
"crc": "^3.8.0",
|
"crc": "^3.8.0",
|
||||||
"pinia": "^2.0.23",
|
"pinia": "^2.0.23",
|
||||||
|
@ -4,8 +4,8 @@ import { useEtherStore } from "../store/ether";
|
|||||||
import { ref } from "vue";
|
import { ref } from "vue";
|
||||||
import { NetworkEnum } from "@/model/NetworkEnum";
|
import { NetworkEnum } from "@/model/NetworkEnum";
|
||||||
import blockchain from "../utils/blockchain";
|
import blockchain from "../utils/blockchain";
|
||||||
import ethereumImage from "../assets/ethereum.svg"
|
import ethereumImage from "../assets/ethereum.svg";
|
||||||
import polygonImage from "../assets/polygon.svg"
|
import polygonImage from "../assets/polygon.svg";
|
||||||
|
|
||||||
// Store reference
|
// Store reference
|
||||||
const etherStore = useEtherStore();
|
const etherStore = useEtherStore();
|
||||||
@ -50,12 +50,12 @@ const closeMenu = () => {
|
|||||||
|
|
||||||
const getNetworkImage = (networkName: NetworkEnum) => {
|
const getNetworkImage = (networkName: NetworkEnum) => {
|
||||||
let validImages = {
|
let validImages = {
|
||||||
"Ethereum": ethereumImage,
|
Ethereum: ethereumImage,
|
||||||
"Polygon": polygonImage,
|
Polygon: polygonImage,
|
||||||
}
|
};
|
||||||
|
|
||||||
return validImages[networkName];
|
return validImages[networkName];
|
||||||
}
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@ -81,7 +81,7 @@ const getNetworkImage = (networkName: NetworkEnum) => {
|
|||||||
]
|
]
|
||||||
"
|
"
|
||||||
@mouseover="currencyMenuHoverToggle = true"
|
@mouseover="currencyMenuHoverToggle = true"
|
||||||
@mouseout="currencyMenuHoverToggle = false;"
|
@mouseout="currencyMenuHoverToggle = false"
|
||||||
:style="{
|
:style="{
|
||||||
backgroundColor: currencyMenuOpenToggle
|
backgroundColor: currencyMenuOpenToggle
|
||||||
? '#F9F9F9'
|
? '#F9F9F9'
|
||||||
@ -90,7 +90,10 @@ const getNetworkImage = (networkName: NetworkEnum) => {
|
|||||||
: 'transparent',
|
: 'transparent',
|
||||||
}"
|
}"
|
||||||
>
|
>
|
||||||
<img alt="Choosed network image" :src="getNetworkImage(etherStore.networkName)" />
|
<img
|
||||||
|
alt="Choosed network image"
|
||||||
|
:src="getNetworkImage(etherStore.networkName)"
|
||||||
|
/>
|
||||||
<span
|
<span
|
||||||
class="default-text group-hover:text-gray-900"
|
class="default-text group-hover:text-gray-900"
|
||||||
:style="{
|
:style="{
|
||||||
@ -126,7 +129,7 @@ const getNetworkImage = (networkName: NetworkEnum) => {
|
|||||||
>
|
>
|
||||||
<div class="mt-2">
|
<div class="mt-2">
|
||||||
<div class="bg-white rounded-md z-10">
|
<div class="bg-white rounded-md z-10">
|
||||||
<div
|
<div
|
||||||
class="menu-button gap-2 px-4 rounded-md cursor-pointer"
|
class="menu-button gap-2 px-4 rounded-md cursor-pointer"
|
||||||
@click="etherStore.setNetworkName(NetworkEnum.ethereum)"
|
@click="etherStore.setNetworkName(NetworkEnum.ethereum)"
|
||||||
>
|
>
|
||||||
@ -136,16 +139,14 @@ const getNetworkImage = (networkName: NetworkEnum) => {
|
|||||||
height="20"
|
height="20"
|
||||||
src="@/assets/ethereum.svg"
|
src="@/assets/ethereum.svg"
|
||||||
/>
|
/>
|
||||||
<span
|
<span class="text-gray-900 py-4 text-end font-semibold text-sm">
|
||||||
class="text-gray-900 py-4 text-end font-semibold text-sm"
|
|
||||||
>
|
|
||||||
Ethereum
|
Ethereum
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="w-full flex justify-center">
|
<div class="w-full flex justify-center">
|
||||||
<hr class="w-4/5" />
|
<hr class="w-4/5" />
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="menu-button gap-2 px-4 rounded-md cursor-pointer"
|
class="menu-button gap-2 px-4 rounded-md cursor-pointer"
|
||||||
@click="etherStore.setNetworkName(NetworkEnum.polygon)"
|
@click="etherStore.setNetworkName(NetworkEnum.polygon)"
|
||||||
>
|
>
|
||||||
@ -155,9 +156,7 @@ const getNetworkImage = (networkName: NetworkEnum) => {
|
|||||||
height="20"
|
height="20"
|
||||||
src="@/assets/polygon.svg"
|
src="@/assets/polygon.svg"
|
||||||
/>
|
/>
|
||||||
<span
|
<span class="text-gray-900 py-4 text-end font-semibold text-sm">
|
||||||
class="text-gray-900 py-4 text-end font-semibold text-sm"
|
|
||||||
>
|
|
||||||
Polygon
|
Polygon
|
||||||
</span>
|
</span>
|
||||||
<hr />
|
<hr />
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
export enum NetworkEnum {
|
export enum NetworkEnum {
|
||||||
ethereum = "Ethereum",
|
ethereum = "Ethereum",
|
||||||
polygon = "Polygon"
|
polygon = "Polygon",
|
||||||
};
|
}
|
||||||
|
32
src/utils/alchemy.ts
Normal file
32
src/utils/alchemy.ts
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import { Network, Alchemy } from "alchemy-sdk";
|
||||||
|
import { useEtherStore } from "@/store/ether";
|
||||||
|
|
||||||
|
const getAlchemy = () => {
|
||||||
|
const possibleSettings = {
|
||||||
|
Ethereum: {
|
||||||
|
apiKey: import.meta.env.VITE_GOERLI_API_KEY,
|
||||||
|
network: Network.ETH_GOERLI,
|
||||||
|
},
|
||||||
|
Polygon: {
|
||||||
|
apiKey: import.meta.env.VITE_MUMBAI_API_KEY,
|
||||||
|
network: Network.MATIC_MUMBAI,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const etherStore = useEtherStore();
|
||||||
|
|
||||||
|
const settings = possibleSettings[etherStore.networkName];
|
||||||
|
const alchemy = new Alchemy(settings);
|
||||||
|
return alchemy;
|
||||||
|
};
|
||||||
|
|
||||||
|
const showLatestBlockNumber = async () => {
|
||||||
|
const alchemy = getAlchemy();
|
||||||
|
|
||||||
|
const latestBlock = await alchemy.core.getBlockNumber();
|
||||||
|
if (latestBlock) console.log(latestBlock);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default {
|
||||||
|
getAlchemy,
|
||||||
|
showLatestBlockNumber,
|
||||||
|
};
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user