magic-js
magic-js copied to clipboard
Accessing Ethereum user's account from non-view React modules (e.g Redux sagas)
✅ Prerequisites
- [x] Did you perform a cursory search of open issues? Is this question already asked elsewhere?
- [x] Are you reporting to the correct repository (
magic-sdk
)?
❓ Question
Hi there,
I was wondering if there's any way to access user's ephemeral private keys from React components that are not presentational and thus do not include the <m.relayer>. An example could be a redux saga that executes asynchronous code. In a saga, after the user is successfully authenticated, the following code snippet hangs:
const signer = provider.getSigner();
// Get user's Ethereum public address
const address = await signer.getAddress(); // This never resolves
Same would happen to logic components and middlewares. As per the documentation, "After encryption of the keys with the HSM, the encrypted key is then stored on the client-side iframe as well as uploaded to the Magic auth relayer for redundancy, in case the encrypted key on the client-side is accidentally removed." Does this mean that every interaction with the blockchain that requires a signer has to performed inside presentational components that include the iframe <m.relayer>?
🌎 Environment
Software | Version(s) |
---|---|
"@magic-sdk/react-native" | "^2.7.1" |
Browser | React-Native |
yarn |
1.22.4 |
Operating System | MacOs Catalina 10.15.6 |
You can invoke your Magic instance from anywhere in your React Native app, but for the response to process, you'll need to be rendering <m.Relayer>
somewhere (anywhere). I recommend adding <m.Relayer>
in the root component of your app!
Thanks for your response @smithki , unfortunately that doesn't seem to work.. have you guys tried it before? Curious to see if there might be something wrong on my end.
@JavierTrujilloG Sorry for the late reply. I'll take a look using redux saga