2

When creating a dApp using Elrond Network, I need to authenticate a user without actually sending a transaction.

For other blockchains like Ethereum this is achieved using MetaMask which can sign a message and you can be sure that the user is who he sais he is.

I noticed that Elrond Wallet has a "Sign" feature but I'm unsure of how this would be used from the outside or how can I prompt the user to sign a message and send it back.

Can I use Maiar extension or Elrond Wallet to sign a message?

Razvan M.
  • 407
  • 5
  • 14

2 Answers2

7

If you are not doing so already, I suggest you to use erdjs or the dapp package (which includes erdjs) to build your dapp.

Using those you will get the various signing providers that elrond made. This includes:

All of these providers allow you to login, sign transactions, send transactions and also to sign custom messages.

Example code to login via the ExtensionProvider:

let provider = ExtensionProvider.getInstance();
await provider.init();
let walletAddress = await provider.login();
let message = new SignableMessage({message: "Sign this message to make sure you are logged in"});
let signedMessage = await provider.signMessage(message);

Of course using the signed message in this case is optional, but can be useful if you plan to implement some server side authentication flow.

Martin W
  • 733
  • 4
  • 12
  • The sample code is EXACTLY what I've been looking for, but I must check on how this works in an Angular application as there have been some issues with the latest version of Angular as described in another question here: https://stackoverflow.com/questions/69507043/is-there-a-fix-workaround-for-making-erdjs-work-with-angular-12 Will come back with results on how this worked for our system. – Razvan M. Oct 09 '21 at 21:04
1

Contributing to Martin W answer:

dapp package is deprecated. Use dapp-core instead

Rodrigo Vila
  • 27
  • 1
  • 6