@keystonehq/polkadotsnap-adapter
v0.0.1
Published
Adapter for installing Polkadot
Downloads
1
Readme
Polkadot adapter
Polkadot snap adapter is used to integrate Polkadot Snap into your dapp.
Installation
with yarn
yarn add @keystonehq/polkadotsnap-adapter
with npm
npm install @keystonehq/polkadotsnap-adapter
Integration Example
const defaultSnapId = 'npm:@keystonehq/polkadotsnap';
const network = 'polkadot';
import { enablePolkadotSnap } from '@keystonehq/polkadotsnap-adapter';
//Enable `Polkadot Snap` in your dapp
await enablePolkadotSnap(snapId, network, 'latest');
// Get a Polkadot Account
await web3Enable(defaultSnapId);
const ss58Format = {
polkadot: 0,
kusama: 2,
westend: 42,
}[network]
const allAccounts = await web3Accounts({
accountType: 'ethereum',
extensions: 'Polkadot Snap',
ss58Format
});
console.log(allAccounts[0]); //12BbTyvDeeeXWQeu3FNDVZg97sN1TF9E7AksFM6qGpzXMRZK
// Sign Transaction
const injector = await web3FromSource(account.meta.source);
if (injector && injector.signer && injector.signer.signPayload) {
const {signPayload} = injector.signer;
const convertedAmount = BigInt('100000');
const {unsigned, metadataRpc, registry} = await generateTransactionPayload(
'5DVHh78wx4FcWYBtBsEdBEy8Vydk3DrGcd7scpMVDGM1Y4Ro',
convertedAmount.toString(),
);
const signerResult = await signPayload(unsigned);
const signature = u8aToHex(u8aConcat(SIG_TYPE_ED25519, hexToU8a(signerResult.signature)))
const tx = construct.signedTx(unsigned, signature, { metadataRpc, registry });
const provider = new WsProvider(`wss://${network}-rpc.polkadot.io/`);
const api = ApiPromise.create({ provider });
const txHash = await api.rpc.author.submitExtrinsic(tx);
}