Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Signing transactions with ethers/ viem #3033

Closed
dudo50 opened this issue Nov 6, 2024 · 3 comments
Closed

Signing transactions with ethers/ viem #3033

dudo50 opened this issue Nov 6, 2024 · 3 comments

Comments

@dudo50
Copy link

dudo50 commented Nov 6, 2024

Hello, is it possible to sign Moonbeam transactions with ethers or viem signers?
ph

Because we had no success with this. Is there any function to convert Ethers to Substrate EVM signer? Thanks!

@dudo50 dudo50 changed the title Signing transactions with ethers/ viem Signing EVM Parachain transactions with ethers/ viem Nov 6, 2024
@dudo50 dudo50 changed the title Signing EVM Parachain transactions with ethers/ viem Signing transactions with ethers/ viem Nov 6, 2024
@RomarQ
Copy link
Contributor

RomarQ commented Nov 6, 2024

You can do this for substrate transactions:

import { Keyring } from "@polkadot/api";
import type { KeyringPair } from "@polkadot/keyring/types";

const keyringEth = new Keyring({ type: "ethereum" });

export const signer: KeyringPair = keyringEth.addFromUri("0x...private_key");

tx.signAndSend(signer);

@dudo50
Copy link
Author

dudo50 commented Nov 6, 2024

@RomarQ that would, however, require us to have the private key of the user. We get the ethers signer from the wallet connect component so we do not have their private key. Is there any workaround on how to convert ethers to substrate-compatible signers? Thanks!

@RomarQ
Copy link
Contributor

RomarQ commented Nov 7, 2024

You can use wallets like (Talisman and SubWallet) which offer support for both Substrate and Ethereum ecosystems.

If you want a other solution, you will need to handle the encoding and use a different signing method for substrate transactions, since signMessage does some special things to the data being signed (something like eth_sign(message) => sign(keccak256("\x19Ethereum Signed Message:\n" + len(message) + message))))

@RomarQ RomarQ closed this as completed Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants