Connect & Disconnect
The JavaScript library provides two primary functions, connect and disconnect. The library encapsulates the complex authentication logic (authenticate to Ceramic Network) into easy-to-use functions. The source code can be found here.

User Flow

In general, there are two steps needed from users to write connection data.

1.Initialize action

The user start by clicking the follow/unfollow button in the website, it should invoke connect function in the JavaScript library.

2. Sign MetaMask message

This step is needed only when its user's first action in the current session. The user doesn't need to sign MetaMask message again for the following actions.
After user signed the first message, the library will generate a derived signing key stored in the memory for future safe interaction with Ceramic Network.

Installation

1
npm install @cyberlab/cyberconnect
2
or
3
yarn add @cyberlab/cyberconnect
Copied!

Basic Usage

Init CyberConnect
1
import CyberConnect, {
2
Env,
3
Blockchain,
4
} from 'npm install @cyberlab/cyberconnect';
5
6
const cyberConnect = new CyberConnect({
7
namespace: 'CyberConnect',
8
env: Env.Production,
9
chain: Blockchain.ETH,
10
provider: provider,
11
});
Copied!
  • namespace - Your application name.
  • env - (optional) Env decides the endpoints. Now we have staging and production. (The default value is Env.Production).
  • chain - (optional) The blockchain you want to connect with. Now we support Ethereum and Solana. (The default is Blockchain.ETH).
  • provider - The corresponding provider of the given chain.
Connect
1
cyberConnect.connect(targetAddr, alias);
Copied!
  • targetAddr - The target wallet address to connect.
  • alias - (optional) Alias for the target address.
Disconnect
1
cyberConnect.disconnect(targetAddr);
Copied!
  • targetAddr - The target wallet address to disconnect.

Solana

You can get Solana provider from @solana/wallet-adapter-react
1
import { useWallet } from '@solana/wallet-adapter-react';
2
const solanaProvider = useWallet();
Copied!
Note: You need to pass chainRef when you connect to Solana. Now we have three options: Solana.SOLANA_MAINNET_CHAIN_REF, Solana.SOLANA_DEVNET_CHAIN_REF and Solana.SOLANA_TESTNET_CHAIN_REF
1
import CyberConnect, {
2
Env,
3
Blockchain,
4
Solana,
5
} from 'npm install @cyberlab/cyberconnect';
6
7
const cyberConnect = new CyberConnect({
8
namespace: 'CyberConnect',
9
env: Env.Production,
10
chain: Blockchain.ETH,
11
provider: solanaProvider,
12
chainRef: Solana.SOLANA_MAINNET_CHAIN_REF,
13
});
Copied!
Last modified 1d ago