Retrieve signer from WalletConnect #160
Unanswered
nicolapertosa
asked this question in
Q&A
Replies: 1 comment
-
Hello @nicolapertosa, WalletConnect and browser extensions like Polkadot Extension-dApp operate differently. Browser extensions inject an account into the web page. You are right, the signer used by these extensions is typically a private key associated with the user's account, rather than a signed transaction hash. WalletConnect is a protocol, you have to initialize a client instance and trigger a const TERNOA_ALPHANET_CHAIN = "ternoa:18bcdb75a0bba577b084878db2dc2546";
// For mainnet => ternoa:6859c81ca95ef624c9dfe4dc6e3381c3
export const signWC = async (tx: string, nonce?: number): Promise<`0x${string}`> => {
if (typeof client === 'undefined') {
reset()
throw new Error('WalletConnect is not initialized')
}
if (typeof session === 'undefined') {
reset()
throw new Error('Session is not connected')
}
if (account === undefined) {
reset()
throw new Error('Account is not connected')
}
const resPromise = await client.request({
request: {
method: 'sign_transaction',
params: {
pubKey: account.split(':')[2],
request: {
hash: tx,
nonce: nonce,
validity: undefined,
submit: false,
},
},
},
topic: session.topic,
chainId: TERNOA_ALPHANET_CHAIN,
})
const promises = [resPromise, sleepFunction(() => redirectToAppIfMobile(), 1000)]
const values = await Promise.all(promises)
return JSON.parse(values[0] as any).signedTxHash
} A tutorial covering Wallet Connect full flow is available here: wallet-connect-integration/TUTORIAL.md |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
I try to make a fund transfer with the SDK and interacting with WalletConnect.
But to submit my transaction to the blockchain, I need to provide the signer.
My question is, how do I get this signer from WalletConnect ?
And I guess the signer is not the signed transaction hash...
const signedTx = ( await api.tx(txHex).signAsync(account, { nonce, **signer** }) ).toHex();
Thank you for your help.
Beta Was this translation helpful? Give feedback.
All reactions