What is Plutonication

                    Examples in Javascript
                

Plutonication allows users to connect PlutoWallet to other dApps seamlessly on any platforms, accross multiple codebases. DApp just generates a QR code and once it is scanned in the wallet, they will pair and the wallet will be able to receive transaction requests from the dApp. It works on the same principle as WalletConnect protocol.

Installation


import {
    AccessCredentials,
    initializePlutonicationWalletClient,
    initializePlutonicationWalletClientWithModal
} from '@plutonication/plutonication'
                

Use this command: npm i @plutonication/plutonication.

After the installation succeeds, do not forget to import it.

Access Credentials

                    
const accessCredentials = new AccessCredentials(
    // Address of Plutonication server
    // Feel free to use this one
    "wss://plutonication.com/",

    // dApp name
    "Plutonication test",

    // dApp icon
    "https://rostislavlitovkin.pythonanywhere.com/plutowalleticonwhite"
)
                 

To use PlutonicationDAppClient, you need to provide the AccessCredentials with the necessary information.

But do not worry, it is this easy.

Feel free to use the wss://plutonication.com/ address. You might also choose to deploy your own Plutonication server. The guide on how to deploy it can be found here.

DApp name and dApp icon properties are shown in the wallet upon requesting connection.

Initialize Plutonication

                    
// Get the Plutonication account
const account = await initializePlutonicationDAppClientWithModal(
    // Include your access credentials
    accessCredentials,

    // Optinally add extra behaviour on when the wallet successfully connects
    (receivedPubkey) => {
        console.log("receivedPubkey", receivedPubkey);
    },
)

// Do not forget to include <plutonication-modal></plutonication-modal>
// on the place where you want to include the Plutonication modal.
                 

The following method initializes PlutonicationDAppClient and reveals <plutonication-modal></plutonication-modal>.

It also returns you the account object of type Injected. This account object can be used the same way as you would the injector from the Polkadot.js/extension.

Advanced use

                    
// Get the Plutonication account
const account = await initializePlutonicationDAppClient(
    // Include your access credentials
    accessCredentials,

    // Optinally add extra behaviour on when the wallet successfully connects
    (receivedPubkey) => {
        console.log("receivedPubkey", receivedPubkey);
    },
)

// Do not forget to include <plutonication-modal></plutonication-modal>
// on the place where you want to include the Plutonication modal.
                 

The following method just initializes PlutonicationDAppClient. It does not reveal any <plutonication-modal></plutonication-modal>.

This method is meant for more advanced use cases. It is totally up to you how you transfer the accessCredentials information to the wallet. Without the plutonication-modal, you have to create your own QR code or you have to use any other method.

It also returns you the account object of type Injected. This account object can be used the same way as you would the injector from the Polkadot.js/extension.

Wallet client

                    
// any KeyringPair account
const alice = getAlice()

const walletClient = await initializePlutonicationWalletClient(
    // Your Access Credentials
    accessCredentials,

    // Account public address
    alice.address,

    // Payload signing logic
    async (payload: SignerPayloadJSON) => {
        // Feel free to change this logic to fit your needs

        const signingPayload = api.registry.createType("ExtrinsicPayload", payload, {
            version: payload.version,
        });

        console.log(`Payload to Sign ${signingPayload.toHex()}`);

        let message = signingPayload.toU8a({ method: true });
        // If the message is too long, hash it
        if (message.length > 256) {
            message = api.registry.hash(message); // blake2b_256
        }

        const signature = alice.sign(message)

        // Do not forget to send the signature back to dApp
        walletClient.send_payload_signature({ signature: u8aToHex(signature), id: 0 })
    },

    // Raw message signing logic
    async (raw: SignerPayloadRaw) => {
        // Feel free to change this logic to fit your needs

        const signature = alice.sign(hexToU8a(raw.data))

        // Do not forget to send the signature back to dApp
        walletClient.send_raw_signature({ signature: u8aToHex(signature), id: 0 })
    },
)
                 

If you are developing your own crypto wallet and you want to add Plutonication into your app, then you are at the right place.

By calling initializePlutonicationWalletClient with all correct arguments, you will initialize the wallet client in the background. You do not have to do anything else.

Yes, It works like a magic!