Cannot read property 'SiweMessage' of undefined
Closed this issue · 3 comments
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.
I had the same issue, did you find any solution?
@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!
I am able to successfully generate, sign and verify a message with the given parameters in the issue (replacing address with a valid address). It's possible an existing bug at time of issue creation has since been fixed.