1

I'm trying to allow users on the client side send an api.tx.system.remark( 'message' ); with PolkadotJS.

I run into issues on signing and sending the transaction, as I will not have their secret key. I've read through the docs and I have a hugeeeeeee knowledge gap here on what should be done. My next steps are to sift through the PolkadotJS API but it's pretty lean code and will take some time....StackExchange heroes help me!

How do I 'pass' my transaction to the PolkadotJS extension to validate the transaction (if that makes sense).

Below is an image of my (semi-completed) code, addFromUri(${MNEMONIC}) is not an option (as the client is any user and their secret key is inaccessible.

Thanks in advance.

enter image description here

2 Answers 2

3

To integrate with the extension, see this usage info as well as a slightly different sample in the cookbook.

Basically you get a list of accounts from the extension and then attach a signer, from the extension, when doing the signAndSend.

0

:S

It was right in front of me, in the docs. Jeez, I'm getting old. Thanks Jaco, From the docs linked above, this is what I ended up using.


const account = allAccounts[0];


const transferExtrinsic = api.tx.balances.transfer('5C5555yEXUcmEJ5kkcCMvdZjUo7NGJiQJMS7vZXEeoMhj3VQ', 123456)


const injector = await web3FromSource(account.meta.source);


transferExtrinsic.signAndSend(account.address, { signer: injector.signer }, ({ status }) => {
    if (status.isInBlock) {
        console.log(`Completed at block hash #${status.asInBlock.toString()}`);
    } else {
        console.log(`Current status: ${status.type}`);
    }
}).catch((error: any) => {
    console.log(':( transaction failed', error);
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.