DEV Community

EgorMajj
EgorMajj

Posted on

1 1

Руководство по созданию расширения кошелька

В этом руководстве мы будем использовать "Petra Aptos Wallet". В этом руководстве рассказывается о том, как установить расширение Petra и как использовать его в вашем dApp.

  1. Установите Petra в Chrome
  2. Функциональность кошелька
  3. Интеграция dApp

Шаг 1. Установите кошелек в Chrome

  1. Перейдите на страницу руководство по установке расширения Petra.
  2. Нажмите кнопку Добавить в Chrome.

Теперь вы должны увидеть "Petra Aptos Wallet" в ваших расширениях Chrome!

Подсказка: Откройте загруженное расширение, нажав на значок с изображением кусочка головоломки на панели инструментов Chrome.

Шаг 2. Функциональные возможности кошелька

В кошельке внедрены некоторые основы взаимодействия с Aptos

  • Создать новую учетную запись
  • Пополнить учетную запись тестовыми coins
  • Отправить coins на другой адрес
  • Связываться с ресурсами аккаунта в Explorer
  • Просматривать и создавать NFT
  • Выберите различные сети

Шаг 3. Интеграция dApp

dApps могут делать запросы к кошельку со своего сайта:

  • connect(): просит пользователя разрешить соединение с dApp (необходимо для выполнения других запросов)
  • isConnected(): показывает, установило ли dApp соединение с кошельком
  • account(): получает адрес учетной записи, подписанной в кошельке
  • signAndSubmitTransaction(transaction): подписывает данную транзакцию и отправляет в сеть
  • signTransaction(transaction): подписывает данную транзакцию и возвращает ее для отправки в dApp
  • disconnect(): Удаляет соединение между dApp и кошельком. Применяется, когда пользователь хочет удалить соединение.

Использование

// import transaction build from aptos sdk: https://github.com/aptos-labs/aptos-core/tree/main/ecosystem/typescript/sdk
import { BCS, TxnBuilderTypes } from 'aptos';

// Establish connection to the wallet
const result = await (window as any).aptos.connect()

// Check connection status of wallet
const status = await (window as any).aptos.isConnected()

// Gets the address of the account signed into the wallet
const accountAddress = await (window as any).aptos.account()

// Create a transaction
const transaction = {
    arguments: [address, '717'],
    function: '0x1::coin::transfer',
    type: 'entry_function_payload',
    type_arguments: ['0x1::aptos_coin::AptosCoin'],
};

// Send transaction to the extension to be signed and submitted to chain
const response = await (window as any).aptos.signAndSubmitTransaction(transaction)

// Send transaction to the extension to be signed and returns
const signedTransaction = await (window as any).aptos.signTransaction(transaction)

// Disconnect dApp from the wallet
await (window as any).aptos.disconnect(transaction)
Enter fullscreen mode Exit fullscreen mode

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay