Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@metamask/sdk-communication-layer

Package Overview
Dependencies
Maintainers
10
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@metamask/sdk-communication-layer

  • 0.31.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
214K
increased by3.65%
Maintainers
10
Weekly downloads
 
Created
Source

MetaMask SDK Communication Layer

Installation

yarn add @metamask/sdk-communication-layer

Using

Dapp

import {
  CommunicationLayerPreference,
  MessageType,
  RemoteCommunication,
} from '@metamask/sdk-communication-layer';

const remote = new RemoteCommunication({
  communicationLayerPreference: CommunicationLayerPreference.SOCKET,
});

const { channelId, pubKey } = remote.generateChannelId();

const linkParams = `channelId=${encodeURIComponent(
  channelId,
)}&comm=${encodeURIComponent('socket')}&pubkey=${encodeURIComponent(pubKey)}`;

console.log('Connect to', linkParams);

remote.on(MessageType.MESSAGE, (message) => {
  console.log('New Message', message);
});

remote.on(MessageType.CLIENTS_READY, (message) => {
  console.log('Clients now connected!');
});

MetaMask

import {
  CommunicationLayerPreference,
  MessageType,
  RemoteCommunication,
} from '@metamask/sdk-communication-layer';

const url = new URL(this.state.urlToConnect);

// https://metamask.app.link/connect?channelId=4cddce59-c4ea-4c70-9dbf-d1ddbe8f7a9f&comm=socket&pubkey=BCCKuS6Z26iZkxA1oB69X9DN73dlCYEQa46d0id8MCXdshRHGqI4rVuIeXjMS2vrlq7PkD4nbzb7gEFn%2FJfHz4E%3D
console.log(url.searchParams);

const otherPublicKey = url.searchParams.get('pubkey');
const channelId = url.searchParams.get('channelId');
console.log('otherPublicKey', otherPublicKey);
console.log('channelId', channelId);

const remote = new RemoteCommunicationLib({
  commLayer: 'socket',
  otherPublicKey,
});

remote.connectToChannel({ channelId });

remote.on(MessageType.CLIENTS_READY, () => {
  this.setState({ connected: true });
});

remote.on(MessageType.MESSAGE, (message) => {
  console.log('New message', message);
});

Contacts

Contact the MetaMask SDK team for a complimentary design optimization workshop here

FAQs

Package last updated on 26 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc