链接 Mobile 钱包
BKConnect 是一种基于 Deeplink 的技术实现,帮助开发者从 Dapp 打开 Bitget 移动端钱包并跳转到指定位置(可携带参数),实现与 Bitget 移动端钱包快速稳定的交互。
Bitget Wallet 移动端支持 Deeplink URL
::: 注意:Android 端 H5 请求仅支持 https://bkcode.vip?{params}
。 :::
bitkeep://bkconnect?{params}
https://bkcode.vip?{params}
公共参数
通用请求参数
version -string
接口版本dappName -string
DApp 名称dappIcon -string
DApp 图标action -string-必填
方法名称,根据不同的接口值不同actionID -string-必填
操作的唯一 ID,建议设置为 UUIDredirectUrl -string
回调 URL,以 post 请求或者 deeplink 方式返回 (不能存在 bitkeep 关键字段)
通用返回参数
status -string
接口请求状态,0 表示成功,1 表示失败actionID -string
操作的唯一 ID,值同请求接口 actionID 传参
打开 DApp
接口无回调
action-string-必填
值为DApp
url-string-必填
DApp 地址
iOS
//example https://bkcode.vip?action=dapp&url=https://app.uniswap.org/#/swap
static NSString * kdappScheme = @"https://app.uniswap.org/#/swap";
static NSString * kscheme = @"bitkeep://bkconnect?";
static NSString * khscheme = @"https://bkcode.vip?";
///跳转页面
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[self getUrl]] options:@{} completionHandler:nil];
/// Get the redirected url
- (NSString *)getUrl {
NSMutableString *url = [NSMutableString string];
[url appendString:khscheme];
[url appendString:[self getDappParameterUrl]];
NSString *urlScheme = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
return urlScheme;
}
- (NSString *)getDappParameterUrl {
NSDictionary *parameDict = @{@"action" : @"dapp",
@"url" : kdappScheme,
};
NSMutableString *paramString = [NSMutableString string];
[parameDict.allKeys enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
NSString *paramStr = [NSString stringWithFormat:@"%@=%@",obj,parameDict[obj] ? : @""];
[paramString appendString:paramStr];
if ((idx + 1) != parameDict.allKeys.count) {
[paramString appendString:@"&"];
}
}];
return paramString;
}
//example https://bkcode.vip?action=dapp&url=https://app.uniswap.org/#/swap
static NSString * kdappScheme = @"https://app.uniswap.org/#/swap";
static NSString * kscheme = @"bitkeep://bkconnect?";
static NSString * khscheme = @"https://bkcode.vip?";
///跳转页面
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[self getUrl]] options:@{} completionHandler:nil];
/// Get the redirected url
- (NSString *)getUrl {
NSMutableString *url = [NSMutableString string];
[url appendString:khscheme];
[url appendString:[self getDappParameterUrl]];
NSString *urlScheme = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
return urlScheme;
}
- (NSString *)getDappParameterUrl {
NSDictionary *parameDict = @{@"action" : @"dapp",
@"url" : kdappScheme,
};
NSMutableString *paramString = [NSMutableString string];
[parameDict.allKeys enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
NSString *paramStr = [NSString stringWithFormat:@"%@=%@",obj,parameDict[obj] ? : @""];
[paramString appendString:paramStr];
if ((idx + 1) != parameDict.allKeys.count) {
[paramString appendString:@"&"];
}
}];
return paramString;
}
Java
Uri uri = new Uri.Builder()
.scheme("bitkeep")
.authority("bkconnect")
.appendQueryParameter("action", "dapp")
.appendQueryParameter("url", url)
.appendQueryParameter("version", "1") ///
.build();
try {
Intent intent1 = new Intent(
Intent.ACTION_VIEW,
uri
);
startActivity(intent1);
}catch (Exception e){
Log.e("startActivityFail",e.toString());
}
Uri uri = new Uri.Builder()
.scheme("bitkeep")
.authority("bkconnect")
.appendQueryParameter("action", "dapp")
.appendQueryParameter("url", url)
.appendQueryParameter("version", "1") ///
.build();
try {
Intent intent1 = new Intent(
Intent.ACTION_VIEW,
uri
);
startActivity(intent1);
}catch (Exception e){
Log.e("startActivityFail",e.toString());
}
Dart
//example https://bkcode.vip?action=dapp&url=https://app.uniswap.org/#/swap
final kdappScheme = "https://app.uniswap.org/#/swap";
final queryParameters = {
'action': 'dapp',
'url': kdappScheme,
};
Uri scheme = Uri(scheme: 'bitkeep', queryParameters: queryParameters);
if(await canLaunchUrl(scheme)){
await launchUrl(scheme);
} else {
KLog.e('launch app fail');
}
//example https://bkcode.vip?action=dapp&url=https://app.uniswap.org/#/swap
final kdappScheme = "https://app.uniswap.org/#/swap";
final queryParameters = {
'action': 'dapp',
'url': kdappScheme,
};
Uri scheme = Uri(scheme: 'bitkeep', queryParameters: queryParameters);
if(await canLaunchUrl(scheme)){
await launchUrl(scheme);
} else {
KLog.e('launch app fail');
}
h5
https://bkcode.vip?action=dapp&url={dapp_url}
https://bkcode.vip?action=dapp&url={dapp_url}
切换网络
在 URL 中加入参数 _needChain=主链币
,Bitget Wallet 浏览器会自动插入相应的主链生态代码,比如:
- ETH 网络:
{DAppLink}?_needChain=eth
- BSC 网络:
{DAppLink}?_needChain=bnb
- Heco 网络:
{DAppLink}?_needChain=ht
注意:需要刷新页面。
授权/获取指定地址信息
action-string-必填
值为getAccount
chain-string-必填
链名称,参考Chain 值列表
返回
address-string
账号地址
Java
/*
example
//https://bkcode.vip?chain=eth&action=getAccount
*/
static NSString * kscheme = @"bitkeep://bkconnect?";
static NSString * khscheme = @"https://bkcode.vip?";
///跳转页面
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[self getUrl]] options:@{} completionHandler:nil];
/// 获取跳转的url
/// Get the redirected url
- (NSString *)getUrl {
NSMutableString *url = [NSMutableString string];
[url appendString:khscheme];
[url appendString:[self getAccountParameterUrl]];
NSString *urlScheme = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
return urlScheme;
}
//chain 指定链,例如 eth,btc,trx
- (NSString *)getAccountParameterUrl {
NSDictionary *parameDict = @{@"action" : @"getAccount",
@"chain" : @"eth",
};
NSMutableString *paramString = [NSMutableString string];
[parameDict.allKeys enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
NSString *paramStr = [NSString stringWithFormat:@"%@=%@",obj,parameDict[obj] ? : @""];
[paramString appendString:paramStr];
if ((idx + 1) != parameDict.allKeys.count) {
[paramString appendString:@"&"];
}
}];
return paramString;
}
/*
example
//https://bkcode.vip?chain=eth&action=getAccount
*/
static NSString * kscheme = @"bitkeep://bkconnect?";
static NSString * khscheme = @"https://bkcode.vip?";
///跳转页面
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[self getUrl]] options:@{} completionHandler:nil];
/// 获取跳转的url
/// Get the redirected url
- (NSString *)getUrl {
NSMutableString *url = [NSMutableString string];
[url appendString:khscheme];
[url appendString:[self getAccountParameterUrl]];
NSString *urlScheme = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
return urlScheme;
}
//chain 指定链,例如 eth,btc,trx
- (NSString *)getAccountParameterUrl {
NSDictionary *parameDict = @{@"action" : @"getAccount",
@"chain" : @"eth",
};
NSMutableString *paramString = [NSMutableString string];
[parameDict.allKeys enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
NSString *paramStr = [NSString stringWithFormat:@"%@=%@",obj,parameDict[obj] ? : @""];
[paramString appendString:paramStr];
if ((idx + 1) != parameDict.allKeys.count) {
[paramString appendString:@"&"];
}
}];
return paramString;
}
Java
Uri uri = new Uri.Builder()
.scheme("bitkeep")
.authority("bkconnect")
.appendQueryParameter("action", "getAccount")
.appendQueryParameter("dappIcon", icon)
.appendQueryParameter("actionId", actionId)
.appendQueryParameter("redirectUrl", redirectUrl)
.appendQueryParameter("dappName", name)
.appendQueryParameter("chain", chain)
.appendQueryParameter("version", "1")
.build();
try {
Intent intent1 = new Intent(
Intent.ACTION_VIEW,
uri
);
startActivity(intent1);
}catch (Exception e){
Log.e("startActivityFail",e.toString());
}
Uri uri = new Uri.Builder()
.scheme("bitkeep")
.authority("bkconnect")
.appendQueryParameter("action", "getAccount")
.appendQueryParameter("dappIcon", icon)
.appendQueryParameter("actionId", actionId)
.appendQueryParameter("redirectUrl", redirectUrl)
.appendQueryParameter("dappName", name)
.appendQueryParameter("chain", chain)
.appendQueryParameter("version", "1")
.build();
try {
Intent intent1 = new Intent(
Intent.ACTION_VIEW,
uri
);
startActivity(intent1);
}catch (Exception e){
Log.e("startActivityFail",e.toString());
}
Dart
/*
example
//https://bkcode.vip?chain=eth&action=getAccount
*/
//chain 指定链,例如 eth,btc,trx
final queryParameters = {
'action': 'getAccount',
'chain' : 'eth',
};
Uri scheme = Uri(scheme: 'bitkeep', queryParameters: queryParameters);
if(await canLaunchUrl(scheme)){
await launchUrl(scheme);
} else {
KLog.e('launch app fail');
}
}
/*
example
//https://bkcode.vip?chain=eth&action=getAccount
*/
//chain 指定链,例如 eth,btc,trx
final queryParameters = {
'action': 'getAccount',
'chain' : 'eth',
};
Uri scheme = Uri(scheme: 'bitkeep', queryParameters: queryParameters);
if(await canLaunchUrl(scheme)){
await launchUrl(scheme);
} else {
KLog.e('launch app fail');
}
}
Json
https://bkcode.vip?chain={chain}&action=getAccount
https://bkcode.vip?chain={chain}&action=getAccount
添加 token
action-string-必填
值为addAsset
chain-string-必填
链名称,参考附录-chain 值列表contract-string-必填
token 的合约地址,主链币为 0xsymbol-string-必填
token 的 symbol
返回
status-string
接口请求状态,0 表示成功,1 表示失败
Java
/*
example: https://bkcode.vip?chain=eth&contract=0x3hdh37xxxxxx&symbol=tokennamexxxxx&action=addAsset
*/
static NSString * kscheme = @"bitkeep://bkconnect?";
static NSString * khscheme = @"https://bkcode.vip?";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[self getUrl]] options:@{} completionHandler:nil];
/// Get the redirected url
- (NSString *)getUrl {
NSMutableString *url = [NSMutableString string];
[url appendString:khscheme];
[url appendString:[self getAddAssetParameterUrl]];
NSString *urlScheme = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
return urlScheme;
}
//action addAsset //require
//chain String //eth,btc,trx
//contract String //default 0x
//symbol String //Token name
- (NSString *)getAddAssetParameterUrl {
NSDictionary *parameDict = @{@"action" : @"addAsset",
@"chain" : @"eth",
@"contract" : @"0x3hdh37xxxxxx",
@"symbol" : @"tokennamexxxxx",
};
NSMutableString *paramString = [NSMutableString string];
[parameDict.allKeys enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
NSString *paramStr = [NSString stringWithFormat:@"%@=%@",obj,parameDict[obj] ? : @""];
[paramString appendString:paramStr];
if ((idx + 1) != parameDict.allKeys.count) {
[paramString appendString:@"&"];
}
}];
return paramString;
}
/*
example: https://bkcode.vip?chain=eth&contract=0x3hdh37xxxxxx&symbol=tokennamexxxxx&action=addAsset
*/
static NSString * kscheme = @"bitkeep://bkconnect?";
static NSString * khscheme = @"https://bkcode.vip?";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[self getUrl]] options:@{} completionHandler:nil];
/// Get the redirected url
- (NSString *)getUrl {
NSMutableString *url = [NSMutableString string];
[url appendString:khscheme];
[url appendString:[self getAddAssetParameterUrl]];
NSString *urlScheme = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
return urlScheme;
}
//action addAsset //require
//chain String //eth,btc,trx
//contract String //default 0x
//symbol String //Token name
- (NSString *)getAddAssetParameterUrl {
NSDictionary *parameDict = @{@"action" : @"addAsset",
@"chain" : @"eth",
@"contract" : @"0x3hdh37xxxxxx",
@"symbol" : @"tokennamexxxxx",
};
NSMutableString *paramString = [NSMutableString string];
[parameDict.allKeys enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
NSString *paramStr = [NSString stringWithFormat:@"%@=%@",obj,parameDict[obj] ? : @""];
[paramString appendString:paramStr];
if ((idx + 1) != parameDict.allKeys.count) {
[paramString appendString:@"&"];
}
}];
return paramString;
}
Java
Uri uri = new Uri.Builder()
.scheme("bitkeep")
.authority("bkconnect")
.appendQueryParameter("action", "addAsset")
.appendQueryParameter("contract", contract)
.appendQueryParameter("chain", chain)
.appendQueryParameter("redirectUrl", redirectUrl)
.appendQueryParameter("dappName", name)
.appendQueryParameter("dappIcon", icon)
.appendQueryParameter("symbol", symbol)
.appendQueryParameter("actionId", actionId)
.appendQueryParameter("version", "1")
.build();
try {
Intent intent1 = new Intent(
Intent.ACTION_VIEW,
uri
);
startActivity(intent1);
}catch (Exception e){
Log.e("startActivityFail",e.toString());
}
Uri uri = new Uri.Builder()
.scheme("bitkeep")
.authority("bkconnect")
.appendQueryParameter("action", "addAsset")
.appendQueryParameter("contract", contract)
.appendQueryParameter("chain", chain)
.appendQueryParameter("redirectUrl", redirectUrl)
.appendQueryParameter("dappName", name)
.appendQueryParameter("dappIcon", icon)
.appendQueryParameter("symbol", symbol)
.appendQueryParameter("actionId", actionId)
.appendQueryParameter("version", "1")
.build();
try {
Intent intent1 = new Intent(
Intent.ACTION_VIEW,
uri
);
startActivity(intent1);
}catch (Exception e){
Log.e("startActivityFail",e.toString());
}
Dart
/*
example
//https://bkcode.vip?chain=eth&contract=0x3hdh37xxxxxx&symbol=tokennamexxxxx&action=addAsset
*/
final queryParameters = {
'action': 'addAsset',
'chain' : 'eth',
'contract': '0x3hdh37xxxxxx',
'symbol' : 'tokennamexxxxx',
};
Uri scheme = Uri(scheme: 'bitkeep', queryParameters: queryParameters);
if(await canLaunchUrl(scheme)){
await launchUrl(scheme);
} else {
KLog.e('launch app fail');
}
/*
example
//https://bkcode.vip?chain=eth&contract=0x3hdh37xxxxxx&symbol=tokennamexxxxx&action=addAsset
*/
final queryParameters = {
'action': 'addAsset',
'chain' : 'eth',
'contract': '0x3hdh37xxxxxx',
'symbol' : 'tokennamexxxxx',
};
Uri scheme = Uri(scheme: 'bitkeep', queryParameters: queryParameters);
if(await canLaunchUrl(scheme)){
await launchUrl(scheme);
} else {
KLog.e('launch app fail');
}
Json
https://bkcode.vip?chain={chain}&contract={contract_addess}&symbol={contract_symbol}&action=addAsset
https://bkcode.vip?chain={chain}&contract={contract_addess}&symbol={contract_symbol}&action=addAsset
发送交易
action-string-必填
值为send
chain-string-必填
链名称,参考附录-chain 值列表contract-string-必填
合约地址,主链币为 0xto-string-必填
收款账号地址amount-string-必填
转账数量memo-string
转账备注
返回
hash-string
转账 hash
Java
/*
example
//https://bkcode.vip?chain=eth&contract=0x3hdh37xxxxxx&symbol=tokennamexxxxx&action=send
*/
static NSString * kscheme = @"bitkeep://bkconnect?";
static NSString * khscheme = @"https://bkcode.vip?";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[self getUrl]] options:@{} completionHandler:nil];
/// Get the redirected url
- (NSString *)getUrl {
NSMutableString *url = [NSMutableString string];
[url appendString:khscheme];
[url appendString:[self getAddAssetParameterUrl]];
NSString *urlScheme = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
return urlScheme;
}
//action send //require
//chain String //eth,btc,trx
//contract String //default 0x
//to String
//amount String //require
//memo String //optional
- (NSString *)getSendParameterUrl {
NSDictionary *parameDict = @{@"action" : @"send",
@"chain" : @"eth",
@"contract" : @"0x3hdh37xxxxxx",
@"to" : @"0x3hxxxxdh37xxxxxx",
@"amount" : @"0.1",
@"memo" : @"memoMesg",
};
NSMutableString *paramString = [NSMutableString string];
[parameDict.allKeys enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
NSString *paramStr = [NSString stringWithFormat:@"%@=%@",obj,parameDict[obj] ? : @""];
[paramString appendString:paramStr];
if ((idx + 1) != parameDict.allKeys.count) {
[paramString appendString:@"&"];
}
}];
return paramString;
}
/*
example
//https://bkcode.vip?chain=eth&contract=0x3hdh37xxxxxx&symbol=tokennamexxxxx&action=send
*/
static NSString * kscheme = @"bitkeep://bkconnect?";
static NSString * khscheme = @"https://bkcode.vip?";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[self getUrl]] options:@{} completionHandler:nil];
/// Get the redirected url
- (NSString *)getUrl {
NSMutableString *url = [NSMutableString string];
[url appendString:khscheme];
[url appendString:[self getAddAssetParameterUrl]];
NSString *urlScheme = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
return urlScheme;
}
//action send //require
//chain String //eth,btc,trx
//contract String //default 0x
//to String
//amount String //require
//memo String //optional
- (NSString *)getSendParameterUrl {
NSDictionary *parameDict = @{@"action" : @"send",
@"chain" : @"eth",
@"contract" : @"0x3hdh37xxxxxx",
@"to" : @"0x3hxxxxdh37xxxxxx",
@"amount" : @"0.1",
@"memo" : @"memoMesg",
};
NSMutableString *paramString = [NSMutableString string];
[parameDict.allKeys enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
NSString *paramStr = [NSString stringWithFormat:@"%@=%@",obj,parameDict[obj] ? : @""];
[paramString appendString:paramStr];
if ((idx + 1) != parameDict.allKeys.count) {
[paramString appendString:@"&"];
}
}];
return paramString;
}
Java
Uri uri = new Uri.Builder()
.scheme("bitkeep")
.authority("bkconnect")
.appendQueryParameter("action", "send")
.appendQueryParameter("from", from)
.appendQueryParameter("to", to)
.appendQueryParameter("contract", contract)
.appendQueryParameter("amount", amount)
.appendQueryParameter("redirectUrl", redirectUrl)
.appendQueryParameter("dappName", name)
.appendQueryParameter("dappIcon", icon)
.appendQueryParameter("chain", chain)
.appendQueryParameter("memo", "xxxxxmemo")
.appendQueryParameter("actionId", actionId)
.appendQueryParameter("version", "1")
.build();
try {
Intent intent1 = new Intent(
Intent.ACTION_VIEW,
uri
);
startActivity(intent1);
}catch (Exception e){
Log.e("startActivityFail",e.toString());
}
Uri uri = new Uri.Builder()
.scheme("bitkeep")
.authority("bkconnect")
.appendQueryParameter("action", "send")
.appendQueryParameter("from", from)
.appendQueryParameter("to", to)
.appendQueryParameter("contract", contract)
.appendQueryParameter("amount", amount)
.appendQueryParameter("redirectUrl", redirectUrl)
.appendQueryParameter("dappName", name)
.appendQueryParameter("dappIcon", icon)
.appendQueryParameter("chain", chain)
.appendQueryParameter("memo", "xxxxxmemo")
.appendQueryParameter("actionId", actionId)
.appendQueryParameter("version", "1")
.build();
try {
Intent intent1 = new Intent(
Intent.ACTION_VIEW,
uri
);
startActivity(intent1);
}catch (Exception e){
Log.e("startActivityFail",e.toString());
}
Dart
final queryParameters = {
'action': 'send',
'chain' : 'eth',
'contract': '0x3hdh37xxxxxx',
'to' : '0x3hxxxxdh37xxxxxx',
'amount' : '0.1',
'memo' : 'memoMesg',
};
Uri scheme = Uri(scheme: 'bitkeep', queryParameters: queryParameters);
if(await canLaunchUrl(scheme)){
await launchUrl(scheme);
} else {
// KLog.e('launch app fail');
}
final queryParameters = {
'action': 'send',
'chain' : 'eth',
'contract': '0x3hdh37xxxxxx',
'to' : '0x3hxxxxdh37xxxxxx',
'amount' : '0.1',
'memo' : 'memoMesg',
};
Uri scheme = Uri(scheme: 'bitkeep', queryParameters: queryParameters);
if(await canLaunchUrl(scheme)){
await launchUrl(scheme);
} else {
// KLog.e('launch app fail');
}
Json
https://bkcode.vip?chain={chain}&contract={contract_address}&to={to_address}&amount={amount}&memo={memo}&action=addAsset
https://bkcode.vip?chain={chain}&contract={contract_address}&to={to_address}&amount={amount}&memo={memo}&action=addAsset
签名
action-string-必填
值为sign
chain-string-必填
链名称,参考 附录-chain 值列表signType-string-必填
签名类型,支持值有 eth_sign, personal_sign, eth_signTypedData, eth_signTypedData_v3, eth_signTypedData_v4msg-string-必填
签名信息
返回
sign-string
签名信息
Java
/*
example
//https://bkcode.vip?chain=eth&msg=[{"type":"string","name":"Message","value":"Hi, Alice!"},{"type":"uint32","name":"A number","value":"1337"}]&signType=personal_sign&action=sign
///https://bkcode.vip?chain=eth&msg=%5B%7B%22type%22:%22string%22,%22name%22:%22Message%22,%22value%22:%22Hi,%20Alice!%22%7D,%7B%22type%22:%22uint32%22,%22name%22:%22A%20number%22,%22value%22:%221337%22%7D%5D&signType=personal_sign&action=sign
*/
static NSString * kscheme = @"bitkeep://bkconnect?";
static NSString * khscheme = @"https://bkcode.vip?";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[self getUrl]] options:@{} completionHandler:nil];
/// Get the redirected url
- (NSString *)getUrl {
NSMutableString *url = [NSMutableString string];
[url appendString:khscheme];
[url appendString:[self getSignParameterUrl]];
NSString *urlScheme = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
return urlScheme;
}
//action sign //require
//chain String //eth,btc,trx
//signType String //eth_sign personal_sign eth_signTypedData eth_signTypedData_v3 eth_signTypedData_v4
//msg String
- (NSString *)getSignParameterUrl {
NSDictionary *parameDict = @{@"action" : @"sign",
@"chain" : @"eth",
@"signType" : @"personal_sign",
@"msg" : @"[{\"type\":\"string\",\"name\":\"Message\",\"value\":\"Hi, Alice!\"},{\"type\":\"uint32\",\"name\":\"A number\",\"value\":\"13337\"}]",
};
NSMutableString *paramString = [NSMutableString string];
[parameDict.allKeys enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
NSString *paramStr = [NSString stringWithFormat:@"%@=%@",obj,parameDict[obj] ? : @""];
[paramString appendString:paramStr];
if ((idx + 1) != parameDict.allKeys.count) {
[paramString appendString:@"&"];
}
}];
return paramString;
}
/*
example
//https://bkcode.vip?chain=eth&msg=[{"type":"string","name":"Message","value":"Hi, Alice!"},{"type":"uint32","name":"A number","value":"1337"}]&signType=personal_sign&action=sign
///https://bkcode.vip?chain=eth&msg=%5B%7B%22type%22:%22string%22,%22name%22:%22Message%22,%22value%22:%22Hi,%20Alice!%22%7D,%7B%22type%22:%22uint32%22,%22name%22:%22A%20number%22,%22value%22:%221337%22%7D%5D&signType=personal_sign&action=sign
*/
static NSString * kscheme = @"bitkeep://bkconnect?";
static NSString * khscheme = @"https://bkcode.vip?";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[self getUrl]] options:@{} completionHandler:nil];
/// Get the redirected url
- (NSString *)getUrl {
NSMutableString *url = [NSMutableString string];
[url appendString:khscheme];
[url appendString:[self getSignParameterUrl]];
NSString *urlScheme = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
return urlScheme;
}
//action sign //require
//chain String //eth,btc,trx
//signType String //eth_sign personal_sign eth_signTypedData eth_signTypedData_v3 eth_signTypedData_v4
//msg String
- (NSString *)getSignParameterUrl {
NSDictionary *parameDict = @{@"action" : @"sign",
@"chain" : @"eth",
@"signType" : @"personal_sign",
@"msg" : @"[{\"type\":\"string\",\"name\":\"Message\",\"value\":\"Hi, Alice!\"},{\"type\":\"uint32\",\"name\":\"A number\",\"value\":\"13337\"}]",
};
NSMutableString *paramString = [NSMutableString string];
[parameDict.allKeys enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
NSString *paramStr = [NSString stringWithFormat:@"%@=%@",obj,parameDict[obj] ? : @""];
[paramString appendString:paramStr];
if ((idx + 1) != parameDict.allKeys.count) {
[paramString appendString:@"&"];
}
}];
return paramString;
}
Java
//signType: personal_sign eth_signTypedData eth_sign eth_signTypedData_v3 eth_signTypedData_v4
String signType = 'personal_sign';
Uri uri = new Uri.Builder()
.scheme("bitkeep")
.authority("bkconnect")
.appendQueryParameter("action", "sign")
.appendQueryParameter("redirectUrl", redirectUrl)
.appendQueryParameter("dappName", name)
.appendQueryParameter("dappIcon", icon)
.appendQueryParameter("actionId", actionId)
.appendQueryParameter("msg", signMsg)
.appendQueryParameter("chain", chain) ///optional
.appendQueryParameter("signType", signType)
.appendQueryParameter("version", "1")
.build();
try {
Intent intent1 = new Intent(
Intent.ACTION_VIEW,
uri
);
startActivity(intent1);
}catch (Exception e){
Log.e("startActivityFail",e.toString());
}
//signType: personal_sign eth_signTypedData eth_sign eth_signTypedData_v3 eth_signTypedData_v4
String signType = 'personal_sign';
Uri uri = new Uri.Builder()
.scheme("bitkeep")
.authority("bkconnect")
.appendQueryParameter("action", "sign")
.appendQueryParameter("redirectUrl", redirectUrl)
.appendQueryParameter("dappName", name)
.appendQueryParameter("dappIcon", icon)
.appendQueryParameter("actionId", actionId)
.appendQueryParameter("msg", signMsg)
.appendQueryParameter("chain", chain) ///optional
.appendQueryParameter("signType", signType)
.appendQueryParameter("version", "1")
.build();
try {
Intent intent1 = new Intent(
Intent.ACTION_VIEW,
uri
);
startActivity(intent1);
}catch (Exception e){
Log.e("startActivityFail",e.toString());
}
Dart
/*
example
//https://bkcode.vip?chain=eth&msg=[{"type":"string","name":"Message","value":"Hi, Alice!"},{"type":"uint32","name":"A number","value":"1337"}]&signType=personal_sign&action=sign
///https://bkcode.vip?chain=eth&msg=%5B%7B%22type%22:%22string%22,%22name%22:%22Message%22,%22value%22:%22Hi,%20Alice!%22%7D,%7B%22type%22:%22uint32%22,%22name%22:%22A%20number%22,%22value%22:%221337%22%7D%5D&signType=personal_sign&action=sign
*/
//chain, eg: eth,btc,trx
final queryParameters = {
'action': 'sign',
'chain' : 'eth',
'signType': 'personal_sign',
'msg' : '"[{\"type\":\"string\",\"name\":\"Message\",\"value\":\"Hi, Alice!\"},{\"type\":\"uint32\",\"name\":\"A number\",\"value\":\"1337\"}]',
};
Uri scheme = Uri(scheme: 'bitkeep', queryParameters: queryParameters);
if(await canLaunchUrl(scheme)){
await launchUrl(scheme);
} else {
KLog.e('launch app fail');
}
/*
example
//https://bkcode.vip?chain=eth&msg=[{"type":"string","name":"Message","value":"Hi, Alice!"},{"type":"uint32","name":"A number","value":"1337"}]&signType=personal_sign&action=sign
///https://bkcode.vip?chain=eth&msg=%5B%7B%22type%22:%22string%22,%22name%22:%22Message%22,%22value%22:%22Hi,%20Alice!%22%7D,%7B%22type%22:%22uint32%22,%22name%22:%22A%20number%22,%22value%22:%221337%22%7D%5D&signType=personal_sign&action=sign
*/
//chain, eg: eth,btc,trx
final queryParameters = {
'action': 'sign',
'chain' : 'eth',
'signType': 'personal_sign',
'msg' : '"[{\"type\":\"string\",\"name\":\"Message\",\"value\":\"Hi, Alice!\"},{\"type\":\"uint32\",\"name\":\"A number\",\"value\":\"1337\"}]',
};
Uri scheme = Uri(scheme: 'bitkeep', queryParameters: queryParameters);
if(await canLaunchUrl(scheme)){
await launchUrl(scheme);
} else {
KLog.e('launch app fail');
}
Json
https://bkcode.vip?chain={chain}&msg={msg}&signType={sign_type}&action=sign
https://bkcode.vip?chain={chain}&msg={msg}&signType={sign_type}&action=sign