Applications that rely on signMessage for authenticating users can choose to opt-in to one of the various Sign In With (SIW) standards. If a message follows one of the supported standards, Phantom will verify required fields at the time of signing.
The Sign In With Ethereum standard is defined by EIP-4361.
Example
constprovider=getProvider(); // see "Detecting the Provider"constmessage=`magiceden.io wants you to sign in with your Ethereum account:0xb9c5714089478a327f09197987f16f9e5d936e8aClick Sign or Approve only means you have proved this wallet is owned by you.URI: https://magiceden.ioVersion: 1Chain ID: 1Nonce: bZQJ0SL6gJIssued At: 2022-10-25T16:52:02.748ZResources:- https://foo.com- https://bar.com`;constencodedMessage=newTextEncoder().encode(message);constsignedMessage=awaitprovider.signMessage(encodedMessage,"utf8");
constprovider=getProvider(); // see "Detecting the Provider"constmessage=`magiceden.io wants you to sign in with your Ethereum account:0xb9c5714089478a327f09197987f16f9e5d936e8aClick Sign or Approve only means you have proved this wallet is owned by you.URI: https://magiceden.ioVersion: 1Chain ID: 1Nonce: bZQJ0SL6gJIssued At: 2022-10-25T16:52:02.748ZResources:- https://foo.com- https://bar.com`;constencodedMessage=newTextEncoder().encode(message);constsignedMessage=awaitprovider.request({ method:"signMessage", params message: encodedMessage, display:"utf8",});
Sign In With X
The Sign In With X standard is defined by CAIP-122. It uses CAIP-10 identifiers for the address field and CAIP-2 for chain-id.
While CAIP-122 is technically chain-agnostic, only Ethereum and Solana parsing are supported at this time.
Ethereum Example
constprovider=getProvider(); // see "Detecting the Provider"constmessage=`magiceden.io wants you to sign in with your Ethereum account:eip155:1:0xb9c5714089478a327f09197987f16f9e5d936e8aClick Sign or Approve only means you have proved this wallet is owned by you.URI: https://magiceden.ioVersion: 1Chain ID: eip155:1Nonce: bZQJ0SL6gJIssued At: 2022-10-25T16:52:02.748ZResources:- https://foo.com- https://bar.com`;constencodedMessage=newTextEncoder().encode(message);constsignedMessage=awaitprovider.signMessage(encodedMessage,"utf8");java
constprovider=getProvider(); // see "Detecting the Provider"constmessage=`magiceden.io wants you to sign in with your Ethereum account:eip155:1:0xb9c5714089478a327f09197987f16f9e5d936e8aClick Sign or Approve only means you have proved this wallet is owned by you.URI: https://magiceden.ioVersion: 1Chain ID: eip155:1Nonce: bZQJ0SL6gJIssued At: 2022-10-25T16:52:02.748ZResources:- https://foo.com- https://bar.com`;constencodedMessage=newTextEncoder().encode(message);constsignedMessage=awaitprovider.request({ method:"signMessage", params: { message: encodedMessage, display:"utf8",});
Solana Example
constprovider=getProvider(); // see "Detecting the Provider"constmessage=`magiceden.io wants you to sign in with your Solana account:solana:mainnet:FYpB58cLw5cwiN763ayB2sFT8HLF2MRUBbbyRgHYiRpKClick Sign or Approve only means you have proved this wallet is owned by you.URI: https://magiceden.ioVersion: 1Chain ID: solana:mainnetNonce: bZQJ0SL6gJIssued At: 2022-10-25T16:52:02.748ZResources:- https://foo.com- https://bar.com`;constencodedMessage=newTextEncoder().encode(message);constsignedMessage=awaitprovider.signMessage(encodedMessage,"utf8");
constprovider=getProvider(); // see "Detecting the Provider"constmessage=`magiceden.io wants you to sign in with your Solana account:solana:mainnet:FYpB58cLw5cwiN763ayB2sFT8HLF2MRUBbbyRgHYiRpKClick Sign or Approve only means you have proved this wallet is owned by you.URI: https://magiceden.ioVersion: 1Chain ID: solana:mainnetNonce: bZQJ0SL6gJIssued At: 2022-10-25T16:52:02.748ZResources:- https://foo.com- https://bar.com`;constencodedMessage=newTextEncoder().encode(message);constsignedMessage=awaitprovider.request({ method:"signMessage", params message: encodedMessage, display:"utf8",});