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

Cannot read property 'SiweMessage' of undefined #171

Open
ElliotWood13 opened this issue Jun 28, 2023 · 2 comments
Open

Cannot read property 'SiweMessage' of undefined #171

ElliotWood13 opened this issue Jun 28, 2023 · 2 comments

Comments

@ElliotWood13
Copy link

ElliotWood13 commented Jun 28, 2023

Hello, I'm trying to create a message in a React Native Expo app but keep getting a "Cannot read property 'SiweMessage' of undefined" error.

My code:

import siwe from 'siwe';

const siweMessage = new siwe.SiweMessage({
    domain: "192.168.1.233:19000", // the value of window.location.host 
    address: "0x...." , // using an address here
    statement: 'login',
    uri:"http://192.168.1.233:19000", // the value of window.location.origin
    version: '1',
    chainId: 80001, // Polygon Mumbai
  });
  return siweMessage.prepareMessage();

Any help would be much appreciated, thank you.

@MJoaaquin
Copy link

I had the same issue, did you find any solution?

@ElliotWood13
Copy link
Author

ElliotWood13 commented Sep 11, 2023

@MJoaaquin I started adding various props that were classed as optional till I got it working. Here's a code snippet example of what mine looks like..

import { generateNonce, SiweMessage } from 'siwe'; // version "1.1.6"

function createSiweMessage(address: string) {
  const SESSION_DURATION_MS = 1000 * 60 * 60 * 4; // 4 hours (max allowed)
  const expirationDate = new Date(Date.now() + SESSION_DURATION_MS);

  const message = new SiweMessage({
    domain: example.com,
    address: address,
    statement: 'Sign in with Ethereum',
    uri: https://example.com/pathMaybeNeeded,
    version: '1',
    chainId: 80001,
    nonce: generateNonce(),
    expirationTime: expirationDate.toISOString(),
  });

  return message.prepareMessage();
}

It's worth checking if you're calling local host or if you're actually calling an external endpoint with the message.

I hope this helps you!

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