|
| 1 | +<template> |
| 2 | + <div class="flex flex-col max-w-[750px] mx-auto py-10"> |
| 3 | + <button class="btn btn-neutral" @click="connectWallet" v-if="!address">Connect</button> |
| 4 | + <div class="flex flex-col gap-5" v-else> |
| 5 | + <span class="flex flex-col"> |
| 6 | + <span>Connected Wallet Address:</span> |
| 7 | + <span class="font-bold">{{ address }}</span> |
| 8 | + </span> |
| 9 | + |
| 10 | + <labe class="input input-bordered w-full flex items-center gap-2"> |
| 11 | + <span class="w-24 text-gray">Transfer to:</span> |
| 12 | + <input v-model="reciept" type="text" placeholder="Type here" class="w-full" /> |
| 13 | + </labe> |
| 14 | + <button class="btn btn-primary" @click="transfer">Transfer 0.01 APT</button> |
| 15 | + </div> |
| 16 | + </div> |
| 17 | +</template> |
| 18 | + |
| 19 | +<script setup lang="ts"> |
| 20 | + import { onMounted, ref } from 'vue'; |
| 21 | +
|
| 22 | + const address = ref(''); |
| 23 | +
|
| 24 | + const connectWallet = async () => { |
| 25 | + const result: any = await window.petra.connect(); |
| 26 | + address.value = result.address; |
| 27 | + window.localStorage.setItem('petra-wallet', 'yes'); |
| 28 | + }; |
| 29 | +
|
| 30 | + const init = async () => { |
| 31 | + if (window.localStorage.getItem('petra-wallet')) { |
| 32 | + connectWallet(); |
| 33 | + } |
| 34 | + }; |
| 35 | +
|
| 36 | + const reciept = ref('0xe51c64d1f2595557676053e03ce637f9fe26af706c156cae7fff3ad4893ccc53'); |
| 37 | + const transfer = async () => { |
| 38 | + const networkInfo: any = await window.petra.getNetwork(); |
| 39 | + console.log(networkInfo); |
| 40 | +
|
| 41 | + if (networkInfo.chainId != 2) { |
| 42 | + alert('Please switch to testnet'); |
| 43 | + return; |
| 44 | + } |
| 45 | +
|
| 46 | + if (!address.value) { |
| 47 | + alert('Please connect wallet'); |
| 48 | + return; |
| 49 | + } |
| 50 | +
|
| 51 | + if (!reciept.value) { |
| 52 | + alert('Please enter reciept'); |
| 53 | + return; |
| 54 | + } |
| 55 | +
|
| 56 | + const result: any = await window.petra.signAndSubmitTransaction({ |
| 57 | + arguments: [reciept.value, '101'], |
| 58 | + function: '0x1::coin::transfer', |
| 59 | + type: 'entry_function_payload', |
| 60 | + type_arguments: ['0x1::aptos_coin::AptosCoin'], |
| 61 | + }); |
| 62 | + console.log(result); |
| 63 | + alert(`Transaction submitted: ${result.hash}, ${result.vm_status}`); |
| 64 | + }; |
| 65 | +
|
| 66 | + onMounted(() => { |
| 67 | + init(); |
| 68 | + }); |
| 69 | +</script> |
| 70 | + |
| 71 | +<style scoped></style> |
0 commit comments