|
7 | 7 | <span class="font-bold">{{ address }}</span>
|
8 | 8 | </span>
|
9 | 9 |
|
10 |
| - <labe class="input input-bordered w-full flex items-center gap-2"> |
| 10 | + <label class="input input-bordered w-full flex items-center gap-2"> |
11 | 11 | <span class="w-24 text-gray">Transfer to:</span>
|
12 | 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> |
| 13 | + </label> |
| 14 | + |
| 15 | + <div class="grid grid-cols-2 gap-2"> |
| 16 | + <button class="btn btn-primary" @click="bbClientTransfer"> |
| 17 | + Transfer 0.01 APT By boltbunny SDK |
| 18 | + </button> |
| 19 | + <button class="btn btn-primary" @click="transfer">Transfer 0.01 APT</button> |
| 20 | + </div> |
15 | 21 | </div>
|
16 | 22 | </div>
|
17 | 23 | </template>
|
18 | 24 |
|
19 | 25 | <script setup lang="ts">
|
| 26 | + import { |
| 27 | + AccountAddress, |
| 28 | + Aptos, |
| 29 | + AptosConfig, |
| 30 | + Network, |
| 31 | + SimpleTransaction, |
| 32 | + } from '@aptos-labs/ts-sdk'; |
| 33 | + import { WalletCore } from '@aptos-labs/wallet-adapter-core'; |
| 34 | + import { BoltBunnyClient } from '@boltbunny/ts-sdk'; |
| 35 | + import { PetraWallet } from 'petra-plugin-wallet-adapter'; |
20 | 36 | import { onMounted, ref } from 'vue';
|
| 37 | + const wallets = [new PetraWallet()]; |
| 38 | + const walletCore: WalletCore = new WalletCore(wallets); |
| 39 | +
|
| 40 | + walletCore.on('connect', () => { |
| 41 | + console.log(walletCore.account); |
| 42 | + address.value = walletCore.account!.address; |
| 43 | + }); |
21 | 44 |
|
22 | 45 | const address = ref('');
|
| 46 | + const bbClient = new BoltBunnyClient({ |
| 47 | + APISecretKey: 'bb_TESTNET_0_5cGVyv7ZHwXDSnT655ojZXLjJdDfG11B', |
| 48 | + network: Network.TESTNET, |
| 49 | + }); |
| 50 | +
|
| 51 | + const AptosClient = new Aptos( |
| 52 | + new AptosConfig({ |
| 53 | + network: Network.TESTNET, |
| 54 | + }), |
| 55 | + ); |
23 | 56 |
|
24 | 57 | const connectWallet = async () => {
|
25 |
| - const result: any = await window.petra.connect(); |
26 |
| - address.value = result.address; |
27 |
| - window.localStorage.setItem('petra-wallet', 'yes'); |
| 58 | + await walletCore.connect('Petra'); |
| 59 | + window.localStorage.setItem('petra-wallet', 'true'); |
28 | 60 | };
|
29 | 61 |
|
30 | 62 | const init = async () => {
|
|
33 | 65 | }
|
34 | 66 | };
|
35 | 67 |
|
| 68 | + console.log(AccountAddress.from('0x1').toStringLong()); |
| 69 | +
|
| 70 | + const bbClientTransfer = async () => { |
| 71 | + const txn: SimpleTransaction = await AptosClient.transaction.build.simple({ |
| 72 | + sender: address.value, |
| 73 | + data: { |
| 74 | + typeArguments: [ |
| 75 | + '0x0000000000000000000000000000000000000000000000000000000000000001::aptos_coin::AptosCoin', |
| 76 | + ], |
| 77 | + functionArguments: [reciept.value, '101'], |
| 78 | + function: |
| 79 | + '0x0000000000000000000000000000000000000000000000000000000000000001::coin::transfer', |
| 80 | + }, |
| 81 | + withFeePayer: true, |
| 82 | + }); |
| 83 | +
|
| 84 | + const signature = await walletCore.signTransaction(txn); |
| 85 | +
|
| 86 | + try { |
| 87 | + const result: any = await bbClient.sendTransaction({ |
| 88 | + signature: signature.bcsToHex().toString(), |
| 89 | + transaction: txn.rawTransaction.bcsToHex().toString(), |
| 90 | + }); |
| 91 | + console.log(result); |
| 92 | + alert(`Transaction submitted: ${result.submitTransaction.transactionHash}`); |
| 93 | + } catch (e: any) { |
| 94 | + alert('Error: ' + e.message); |
| 95 | + } |
| 96 | + }; |
| 97 | +
|
36 | 98 | const reciept = ref('0xe51c64d1f2595557676053e03ce637f9fe26af706c156cae7fff3ad4893ccc53');
|
37 | 99 | const transfer = async () => {
|
38 |
| - const networkInfo: any = await window.petra.getNetwork(); |
| 100 | + const networkInfo: any = walletCore?.network; |
39 | 101 | console.log(networkInfo);
|
40 | 102 |
|
41 | 103 | if (networkInfo.chainId != 2) {
|
|
53 | 115 | return;
|
54 | 116 | }
|
55 | 117 |
|
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'], |
| 118 | + const txn: any = await walletCore.signAndSubmitTransaction({ |
| 119 | + data: { |
| 120 | + functionArguments: [reciept.value, '101'], |
| 121 | + function: '0x1::coin::transfer', |
| 122 | + typeArguments: ['0x1::aptos_coin::AptosCoin'], |
| 123 | + }, |
| 124 | + }); |
| 125 | + const result: any = await AptosClient.waitForTransaction({ |
| 126 | + transactionHash: txn.hash, |
61 | 127 | });
|
62 |
| - console.log(result); |
63 | 128 | alert(`Transaction submitted: ${result.hash}, ${result.vm_status}`);
|
64 | 129 | };
|
65 | 130 |
|
|
0 commit comments