docs ⦿ dedot 🧑‍💻
TypinkXTelegramGithub
dedot 🧑‍💻
dedot 🧑‍💻
  • Welcome to Dedot
  • Why Dedot?
  • Getting started
    • Installation
    • Connect to network
    • @polkadot/api -> dedot
    • Packages structure
  • Clients & Providers
    • Providers
    • Clients
  • Client API
    • ChainApi
    • Constants
    • Runtime APIs
    • Storage Queries
    • Transactions
    • Events
    • Errors
  • ink! Smart Contracts
    • Introduction
    • Generate Types & APIs
    • Deploy contracts
    • Queries
    • Transactions
    • Events
    • Handle errors
  • CLI
  • Keyring & Signer
  • Runtime upgrades
  • Type system
  • Utilities
    • HexString
    • Uint8Array (U8a)
    • String
    • Hash functions
    • Address
    • BigInt & number
    • Balances
    • Merkleized Metadata
  • Help & FAQ
    • Tutorials
      • Develop ink! dApp using Typink
    • Built with Dedot
    • Forum Posts
    • Telegram
    • Github
    • API Reference
Powered by GitBook
On this page
  • Keyring
  • Signer

Was this helpful?

Edit on GitHub

Keyring & Signer

PreviousCLINextRuntime upgrades

Last updated 8 months ago

Was this helpful?

Keyring

Currently Dedot do not have any official package for creating & managing keys, we recommend using @polkadot/keyring package for this purpose.

Please refer to the of @polkadot/keyring for more details on how to install, create & manage keys.

Please note that @polkadot/keyring is currently using bn.js and wasm blob for some cryptographic implementations, this might increase the overall bundle-size of dapps.

Signer

Dedot APIs are designed to be compatible with and interfaces, so you can sign the transactions with accounts/keys created by a from @polkadot/keyring or signers exposed from any wallets (SubWallet, Talisman, ...).

Signing transactions using IKeyringPair

import { cryptoWaitReady } from '@polkadot/util-crypto';
import { Keyring } from '@polkadot/keyring';

// Setup Keyring & create a KeyringPair
await cryptoWaitReady();
const keyring = new Keyring({ type: 'sr25519' });
const aliceKeyringPair = keyring.addFromUri('//Alice');

// Sign & send transaction
const unsub = await client.tx.balances
    .transferKeepAlive(<destAddress>, 2_000_000_000_000n)
    .signAndSend(aliceKeyringPair, async ({ status }) => {
      console.log('Transaction status', status.type);
      if (status.type === 'BestChainBlockIncluded') { // or status.type === 'Finalized'
        console.log(`Transaction completed at block hash ${status.value.blockHash}`);
        await unsub();
      }
    });

Signing transactions using Signer

// Retrieve signer from SubWallet extension
const injected = await window.injectedWeb3['subwallet-js'].enable('A cool dapp');
const account = (await injected.accounts.get())[0]; // get the first account
const signer = injected.signer;

// Setup global signer
client.setSigner(signer);

// Sign & send transaction
const unsub = await client.tx.balances
    .transferKeepAlive(<destAddress>, 2_000_000_000_000n)
    .signAndSend(account.address, async ({ status }) => {
      console.log('Transaction status', status.type);
      if (status.type === 'BestChainBlockIncluded') { // or status.type === 'Finalized'
        console.log(`Transaction completed at block hash ${status.value.blockHash}`);
        await unsub();
      }
    });

official documentation
IKeyringPair
Signer
Keyring
Polkadot{.js}-extensions-based