# WalletConnect

# EVM(WebApp)

WalletConnect 是一个连接钱包和 DApps(Web3 应用程序)的开放协议,它使用一个桥梁服务器在两个应用程序和/或设备之间建立远程连接,扫描 QR 码建立连接并开始通信。BitKeep 钱包应用程序现在支持 WalletConnect。

更详细的文件,请参考https://docs.walletconnect.com (opens new window)

我们提供一个简单演示 (opens new window)

npm install --save @walletconnect/client @walletconnect/qrcode-modal
1
import WalletConnect from '@walletconnect/client';
import QRCodeModal from '@walletconnect/qrcode-modal';
// Create a connector
const connector = new WalletConnect({
  bridge: 'https://bridge.walletconnect.org', // Required
  qrcodeModal: QRCodeModal,
});
// Check if connection is already established
if (!connector.connected) {
  // create new session
  connector.createSession();
}
// Subscribe to connection events
connector.on('connect', (error, payload) => {
  if (error) {
    throw error;
  }
  // Get provided accounts and chainId
  const { accounts, chainId } = payload.params[0];
});
connector.on('session_update', (error, payload) => {
  if (error) {
    throw error;
  }
  // Get updated accounts and chainId
  const { accounts, chainId } = payload.params[0];
});
connector.on('disconnect', (error, payload) => {
  if (error) {
    throw error;
  }
  // Delete connector
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

# EVM(原生 App SDK)

TIP

前置条件:开发者应用已集成 Wallet Connect (opens new window)

说明

  • 此方案仅支持 EVM 链
  • 如需判断 BitKeep 包名,可联系商务提供包名列表

# 连接钱包

通过 scheme 唤起 BitKeep 钱包, 将 Wallet Connect 数据传输过来。scheme 值请填写bitkeep

# 传递参数说明

参数 参数值说明 备注
uriString 通过 wc 生成器生成相应的 wc 连接 接口获取 有时效性
action 值为 connect
connectType 值为wc

项目方可以在 catch 中根据相应异常进行业务处理。

# 请求代码示例

# Android 请求示例

final String uriString = "wc:e3504282-91c5-4d8b-ae93-6a767532aa20@1?bridge=https%3A%2F%2Fw.bridge.walletconnect.org&key=437444a526c310620482604dd904db09d1f3ef840a7278c5c593a298b3604b22";
final String action = "connect";
final String connectType = "wc";
final Uri uri = new Uri.Builder()
        .scheme("bitkeep")
        .appendQueryParameter("action", action)
        .appendQueryParameter("connectType", connectType)
        .appendQueryParameter("value", uriString)
        .build();
try {
    Intent intent = new Intent(
            Intent.ACTION_VIEW,
            uri
    );
    startActivity(intent);
}catch (Exception e){
    Log.e("startActivityFail",e.toString());
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

# FLutter 请求示例

final  uriString = "wc:xxx?bridge=xxx&key=xxx";
final  action = "connect";
final  connectType = "wc";
 final queryParameters = {
   'action': action,
   'connectType': connectType,
   'value': uriString,
 };
 Uri scheme = Uri(scheme: 'bitkeep', queryParameters: queryParameters);
 if(await canLaunchUrl(scheme)){
   await wlaunchUrl(scheme);
 } else {
   KLog.e('launch app fail');
 }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

# iOS 请求示例

- (NSURL *)getDeepLinkUrl:(NSDictionary *)params {
  NSString *_paramsString = [self encodeParams:params];
  NSString *_deepLinkString = [NSString stringWithFormat:@"bitkeep:?%@",_paramsString];
  return [NSURL URLWithString:_deepLinkString];
}
- (NSString *)encodeParams:(NSDictionary *)params {
  NSMutableString *tmpString = @"".copy;
  for (int i = 0; i < params.allKeys.count; i++) {
    NSString *_tmpValue = [NSString stringWithFormat:@"%@=%@", params.allKeys[i], [params objectForKey:params.allKeys[i]]];
    [tmpString appendString:[NSString stringWithFormat:@"&%@", _tmpValue]];
  }
  return tmpString;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

# Js 请求示例

final String uriString = "wc:e3504282-91c5-4d8b-ae93-6a767532aa20@1?bridge=https%3A%2F%2Fw.bridge.walletconnect.org&key=437444a526c310620482604dd904db09d1f3ef840a7278c5c593a298b3604b22";
final String action = "connect";
final String connectType = "wc";
var linkUrl = 'bitkeep://?action=${action}&connectType=${connectType}&vale=${uriString}'
 <a href= linkUrl/>
1
2
3
4
5
6

# 签名

通过 scheme 唤起 BitKeep 钱包, 将 Wallet Connect 数据传输过来。scheme 值请填写bitkeep

# 传递参数说明

参数 参数值说明
action 值为 sign
connectType 值为wc

# 请求代码示例

# Android 请求示例

final String action = "sign";
final String connectType = "wc";
final Uri uri = new Uri.Builder()
        .scheme("bitkeep")
        .appendQueryParameter("action", action)
        .appendQueryParameter("connectType", connectType)
        .build();
try {
    Intent intent = new Intent(
            Intent.ACTION_VIEW,
            uri
    );
    startActivity(intent);
}catch (Exception e){
    Log.e("startActivityFail",e.toString());
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

# FLutter 请求示例

final  action = "sign";
final  connectType = "wc";
 final queryParameters = {
   'action': action,
   'connectType': connectType,
 };
 Uri scheme = Uri(scheme: 'bitkeep', queryParameters: queryParameters);
 if(await canLaunchUrl(scheme)){
   await wlaunchUrl(scheme);
 } else {
   KLog.e('launch app fail');
 }
1
2
3
4
5
6
7
8
9
10
11
12
13

# iOS 请求示例

- (NSURL *)getDeepLinkUrl:(NSDictionary *)params {
  NSString *_paramsString = [self encodeParams:params];
  NSString *_deepLinkString = [NSString stringWithFormat:@"bitkeep:?%@",_paramsString];
  return [NSURL URLWithString:_deepLinkString];
}
- (NSString *)encodeParams:(NSDictionary *)params {
  NSMutableString *tmpString = @"".copy;
  for (int i = 0; i < params.allKeys.count; i++) {
    NSString *_tmpValue = [NSString stringWithFormat:@"%@=%@", params.allKeys[i], [params objectForKey:params.allKeys[i]]];
    [tmpString appendString:[NSString stringWithFormat:@"&%@", _tmpValue]];
  }
  return tmpString;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

# Js 请求示例

final String action = "sign";
final String connectType = "wc";
var linkUrl = 'bitkeep://?action=${action}&connectType=${connectType}'
 <a href= linkUrl/>
1
2
3
4
5

# 转账

通过 scheme 唤起 BitKeep 钱包, 将 Wallet Connect 数据传输过来。scheme 值请填写bitkeep

# 传递参数说明

参数 参数值说明
action 值为 send
connectType 值为wc

# 请求代码示例

# Android 请求示例

final String action = "send";
final String connectType = "wc";
final Uri uri = new Uri.Builder()
        .scheme("bitkeep")
        .appendQueryParameter("action", action)
        .appendQueryParameter("connectType", connectType)
        .build();
try {
    Intent intent = new Intent(
            Intent.ACTION_VIEW,
            uri
    );
    startActivity(intent);
}catch (Exception e){
    Log.e("startActivityFail",e.toString());
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

# FLutter 请求示例

final  action = "send";
final  connectType = "wc";
 final queryParameters = {
   'action': action,
   'connectType': connectType,
 };
 Uri scheme = Uri(scheme: 'bitkeep', queryParameters: queryParameters);
 if(await canLaunchUrl(scheme)){
   await wlaunchUrl(scheme);
 } else {
   KLog.e('launch app fail');
 }
1
2
3
4
5
6
7
8
9
10
11
12
13

# iOS 请求示例

- (NSURL *)getDeepLinkUrl:(NSDictionary *)params {
  NSString *_paramsString = [self encodeParams:params];
  NSString *_deepLinkString = [NSString stringWithFormat:@"bitkeep:?%@",_paramsString];
  return [NSURL URLWithString:_deepLinkString];
}
- (NSString *)encodeParams:(NSDictionary *)params {
  NSMutableString *tmpString = @"".copy;
  for (int i = 0; i < params.allKeys.count; i++) {
    NSString *_tmpValue = [NSString stringWithFormat:@"%@=%@", params.allKeys[i], [params objectForKey:params.allKeys[i]]];
    [tmpString appendString:[NSString stringWithFormat:@"&%@", _tmpValue]];
  }
  return tmpString;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

# Js 请求示例

final String action = "send";
final String connectType = "wc";
var linkUrl = 'bitkeep://?action=${action}&connectType=${connectType}'
 <a href= linkUrl/>
1
2
3
4
5