Goal: 🎯 Make a transaction to set on-chain identity for connected account
Made by the collaboration between OpenGuild Labs and Dedot to introduce to participants about building decentralized applications on Polkadot.
Learn about the on-chain identity on Polkadot
-
🍭 Easy
Finish the tasks in "Learn how to use Dedot to build an application". -
🍭 Easy
InitializeDedotClient
to connect to Westend People testnet (WestendPeopleApi
) -
🍫 Intermediate
Build a form to enter identity information: Display name, Email, Discord handle -
🍫 Advanced
Make a transaction to set on-chain identity for connected account (viaclient.tx.identity.setIdentity
) -
🍫 Intermediate
Fetch & render your on-chain identity (viaclient.query.identity.identityOf
) -
🍫 Intermediate
If connected account is already set on-chain identity, show the identity information instead the form -
🔥 Advanced
Migrating to light client and install Substrate Connect to connect with your applicaiton.
- ✅ Create a pull request to submit your work for this challenge to the repository.
- ✅ Show your work to the DevRel of OpenGuild and get the confirmation to claim the bounty.
🎯 Build a simple dapp to show & transfer balance on Polkadot testnet
- Install SubWallet Extension: https://www.subwallet.app/download.html
- Create your first wallet
- Enable Polkadot testnet: Rococo & Westend
- Claim testnet token from faucet: https://faucet.polkadot.io/
- Follow instruction at: https://nodejs.org/en/download/package-manager
- Or install via nvm:
# installs nvm (Node Version Manager)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
# download and install Node.js (you may need to restart the terminal)
nvm install 20
# verifies the right Node.js version is in the environment
node -v # should print `v20.15.1`
# verifies the right NPM version is in the environment
npm -v # should print `10.7.0`
- Fork the repo
- Clone the repo
git clone https://github.com/{your-github-username}/openhack-dedot
E.g: https://github.com/sinzii/openhack-dedot
- Install dependencies
npm i
- Start development mode
npm run dev
- The development application starts at: http://localhost:5173
-
🍭 Easy
Connect to wallet -
🍭 Easy
Show connected account (name & address) -
🍭 Easy
InitializeDedotClient
to connect to the network (Westend testnet) -
🍭 Easy
Fetch & show balance for connected account -
🍭 Easy
Build a form to transfer balance (destination address & amount to transfer) -
🍭 Easy
Check transaction status (in-block & finalized) -
🍭 Easy
Check transaction result (success or not) -
🍭 Easy
Subscribe to balance changing
npm i dedot
npm i -D @dedot/chaintypes @polkadot/extension-inject
import { Injected, InjectedAccount, InjectedWindowProvider, InjectedWindow } from '@polkadot/extension-inject/types';
const injectedWindow = window as Window & InjectedWindow;
// Get subwallet-js injected provider to connect with SubWallet
const provider: InjectedWindowProvider = injectedWindow.injectedWeb3['subwallet-js'];
// Connect with SubWallet from the dapp
const injected: Injected = await provider.enable!('Open Hack Dapp');
// Get connected accounts
const accounts: InjectedAccount[] = await injected.accounts.get();
import { DedotClient, WsProvider } from 'dedot';
import { WestendApi } from '@dedot/chaintypes';
import { WESTEND } from './networks.ts';
// initialize the client and connect to the network
const client = new DedotClient<WestendApi>(new WsProvider(WESTEND.endpoint));
await client.connect();
// OR via static factory
const client = await DedotClient.new<WestendApi>(new WsProvider(WESTEND.endpoint));
import { FrameSystemAccountInfo } from '@dedot/chaintypes/westend';
import { formatBalance } from './utils.ts';
import { WESTEND } from './networks.ts';
const account: InjectedAccount = accounts[0]; // get from accounts list - 6.2
const balance: FrameSystemAccountInfo = await client.query.system.account(account.address);
// Get free/transferable balance
const freeBalance = formatBalance(balance.data.free, WESTEND.decimals);
import { Injected, InjectedAccount } from '@polkadot/extension-inject/types';
const client: DedotClinet = ...;
// Get injected instance & connected account - 6.2
const injected: Injected = ...;
const account: InjectedAccount = ...;
const amount: number = 1; // how many token in DOT or WND
// Convert the amount (DOT, or WND) to Planck unit
const amountToTransfer: bigint = BigInt(amount) * BigInt(Math.pow(10, WESTEND.decimals));
const destAddress: string = '...';
await client.tx.balances
.transferKeepAlive(destAddress, amountToTransfer)
.signAndSend(account.address, { signer: injected.signer }, (result) => {
console.log(result.status);
// 'BestChainBlockIncluded': Transaction is included in the best block of the chain
// 'Finalized': Transaction is finalized
if (result.status.type === 'BestChainBlockIncluded' || result.status.type === 'Finalized') {
if (result.dispatchError) {
// Transaction is included but has an error
const error = `${JSON.stringify(Object.values(result.dispatchError))}`;
} else {
// Transaction is included and executed successfully
}
}
});
import { FrameSystemAccountInfo } from '@dedot/chaintypes/westend';
import { formatBalance } from './utils.ts';
import { WESTEND } from './networks.ts';
const account: InjectedAccount = accounts[0]; // get from accounts list - 6.2
// Pass in a callback to be called whenver the balance is changed/updated
const unsub = await client.query.system.account(account.address, (balance: FrameSystemAccountInfo) => {
// Get free/transferable balance
const freeBalance = formatBalance(balance.data.free, WESTEND.decimals);
});
OpenGuild is a builder-driven community centered around Polkadot. OpenGuild is built by Web3 builders for Web3 builders. Our primary aim is to cater to developers seeking a comprehensive understanding of the Polkadot blockchain, providing curated, in-depth materials with a low-level approach.
- About us: Learn more about us
- Website: OpenGuild Website
- Github: OpenGuild Labs
- Discord: Openguild Discord Channel