Set Passcode
Protects wallets
Passcode protects signing and operations that can alter security parameters. Passcode may be enabled or disabled during card configuration at the factory. Also, it’s possible to prohibit removing the passcode from the card once it’s set.
Passcode can consist of letters, digits or special symbols and can be any length.
Passcode can be set only if card.settings.isSettingPasscodeAllowedistrue.

Request

passcode <String> [optional] Passcode to set. If empty, user will be prompted to enter code before operation.
cardId <String> CID, Unique Tangem card ID number.
initialMessage <Message> [optional] This message will be shown in the NFC session dialog. Default: "Tap the card to your phone exactly as it shown above".

Response

This command will return the SuccessResponse (click to see more) object in response.

Example

Swift
Kotlin
Java
JS (React Native)
JS (Cordova)
Dart
JSON-RPC
1
let passcode = "123456" //This parameter can be omitted. Tangem sdk will request the code from the user automatically
2
let cardId = card.cardId
3
4
tangemSdk.setPasscode(passcode, cardId: cardId) { result in
5
switch result {
6
case .success:
7
print("The passcode was set")
8
case .failure(let error):
9
print(error)
10
}
11
}
Copied!
1
val passcode = "123456" //This parameter can be omitted. Tangem sdk will request the code from the user automatically
2
val cardId = card.cardId
3
4
tangemSdk.setPasscode(
5
passcode = passcode,
6
cardId = cardId
7
) { result ->
8
when (result) {
9
is CompletionResult.Success -> {
10
runOnUiThread {
11
Log.d(TAG, "The passcode was set")
12
}
13
}
14
is CompletionResult.Failure -> {
15
runOnUiThread {
16
Log.d(TAG, result.error)
17
}
18
}
19
}
20
}
Copied!
1
String passcode = "123456"; // if omitted, the user will be prompted by TangemSDK to enter it
2
String cardId = card.getCardId();
3
4
tangemSdk.setPasscode(passcode, cardId, null, result -> {
5
if (result instanceof CompletionResult.Success) {
6
SuccessResponse response = ((CompletionResult.Success<SuccessResponse>) result).getData();
7
Log.d(TAG, "The passcode was set");
8
} else if (result instanceof CompletionResult.Failure) {
9
TangemError error = ((CompletionResult.Failure<SuccessResponse>) result).getError();
10
Log.d(TAG, error.getCustomMessage());
11
}
12
return Unit.INSTANCE;
13
});
Copied!
1
const passCode = 'ABCDEF';
2
const cardId = card.id;
3
TangemSdk.setPassCode(passCode, cardId)
4
.then((result) => console.log(result))
5
.catch((err) => console.log(err));
Copied!
1
var passCode = 'ABCDEF';
2
var cardId = card.cardId;
3
var initialMessage = {"body": "body", "header": "header"};
4
var callback = function (response, error) {
5
if (error) {
6
alert({ "error": error });
7
} else {
8
alert({"response": response});
9
}
10
};
11
12
TangemSdk.setPassCode(passCode, cardId, initialMessage, callback);
Copied!
1
Copied!
1
// Request
2
{
3
"jsonrpc":"2.0",
4
"id":1,
5
"method":"set_passcode",
6
"params":{
7
"passcode":"ABCDEFGH"
8
}
9
}
10
11
// Response
12
{
13
"jsonrpc":"2.0",
14
"result":{
15
"cardId":"c000111122223333"
16
},
17
"id":1
18
}
Copied!
Copy link