Skip to main content

Getting Started

First, you need to install the beacon-sdk package.

npm install --save @airgap/beacon-sdk

After that you need to import the Beacon SDK in your code and initialize the WalletClient.

The beacon-sdk will automatically try to establish a connection and listen to all Beacon messages.

caution

The RPC URL that is provided by the DApp can be an insecure http:// connection. The reason for this is because it allows for easy development with a local node, without setting up a local SSL certificate.

Especially the wallet should care about this and potentially show a warning to the user if the RPC URL is not a secure https:// URL.

import {
WalletClient,
BeaconMessageType,
PermissionScope,
PermissionResponseInput,
} from "@airgap/beacon-sdk";
const connectApp = async (): Promise<void> => {
const client = new WalletClient({ name: "My Wallet" });
await client.init(); // Establish P2P connection
client
.connect(async (message) => {
console.log("beacon message", message);
// Let's assume it's a permission request, but we obviously need to handle all request types
if (message.type === BeaconMessageType.PermissionRequest) {
// Here we would show a UI to the user where he can confirm everything that has been requested in the beacon message
// We hardcode a response
const response: PermissionResponseInput = {
type: BeaconMessageType.PermissionResponse,
network: message.network, // Use the same network that the user requested
scopes: [PermissionScope.OPERATION_REQUEST], // Ignore the scopes that have been requested and instead give only operation permissions
id: message.id,
publicKey: "tezos public key",
};
await client.respond(response);
} else {
// Handle all other requests
}
})
.catch((error) => console.error("connect error", error));
};
connectApp().catch((error) => console.error("connect error", error));