Connect Mobile Wallet
BKConnect is a Deeplink-based technology implementation that helps developers open the Bitget mobile wallet from a Dapp and jump to a specified location (portable parameters) to achieve fast and stable interaction with the Bitget mobile wallet.
Bitget Mobile Apps support Deeplink URL
::: Tips:Android only support https://bkcode.vip?{params}
. :::
bitkeep://bkconnect?{params}
https://bkcode.vip?{params}
Common Pramas
Request Pramas
version -string
BKConnect versiondappName -string
DApp NamedappIcon -string
DApp Iconaction-string-Require
actionID-string-Require
Action UUIDredirectUrl -string
Callback URL
Response Pramas
status-string
0 success,1 failactionID-string
Action UUID, same as Request
Open DApp
action
=DApp
name | value type | Require | note |
---|---|---|---|
url | string | Require | DApp link |
No Response
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}
Switch Network
Add _needChain=xxxx
in url:
- ETH:
{DAppLink}?_needChain=eth
- BSC:
{DAppLink}?_needChain=bnb
- Heco:
{DAppLink}?_needChain=ht
Tips:need reload page
Get Account
action
=getAccount
name | value type | Require | note |
---|---|---|---|
chain | string | Require | Chain name, Select from Chain Config |
Response:
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
Add Token
action
=addAsset
name | value type | Require | note |
---|---|---|---|
chain | string | Require | Chain name, Select from Chain Config |
contract | string | Require | default 0x |
symbol | string | Require | token symbol |
Response:
status-string
0 success, 1 fail
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
Send Transaction
action
=send
name | value type | Require | note |
---|---|---|---|
chain | string | Require | Chain name, Select from Chain Config |
contract | string | Require | default 0x |
to | string | Require | receiver address |
amount | string | Require | |
memo | string | optional | tx note |
Response:
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
Sign
action
=sign
name | value type | Require | note |
---|---|---|---|
chain | string | Require | Chain name, Select from Chain Config |
signType | string | Require | [eth_sign/personal_sign/eth_signTypedData/eth_signTypedData_v3,/eth_signTypedData_v4] |
msg | string | Require | sign message |
Response:
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