Quickstart
1. Install SDK
CRUX supports the following platforms:
- Web - https://github.com/cruxprotocol/js-sdk
- Electron apps - https://github.com/cruxprotocol/js-sdk
- React Native - https://github.com/cruxprotocol/rn-sdk
- Java - https://github.com/cruxprotocol/android-sdk
Upcoming:
- Swift (Native iOS)
Instructions
Javascript platforms -
Web, Electron
// Source code: [GitHub](https://github.com/cruxprotocol/js-sdk)
// Install via `npm`: `npm install @cruxpay/js-sdk`
// or include directly as a script -
//`<script src="https://unpkg.com/@cruxpay/js-sdk/dist/cruxpay-sdk-dom.js"/>`
React Native -
// Source code: [GitHub](https://github.com/cruxprotocol/rn-sdk)
// Install npm package `@cruxpay/rn-sdk`
// Add the JitPack repository to your build file in your root build.gradle at the end of repositories.
// Then add `com.github.cruxprotocol:android-sdk:v0.1` as dependency.
// NOTE: Check latest release version at `https://github.com/cruxprotocol/android-sdk/releases`
repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'com.github.cruxprotocol:android-sdk:v0.1'
}
2. Initialize
To initialise the SDK you need a walletClientName.
You can get create and manage your walletClientName
at CRUX Wallet Dashboard. Please feel free to contact us at [email protected] for any registration related queries.
import { CruxPay } from "@cruxpay/js-sdk";
let cruxClient = new CruxPay.CruxClient({
walletClientName: 'testwallet',
privateKey: "6bd397dc89272e71165a0e7d197b288ed5b1e44e1928c25455506f1968f"
});
// Some operations require a privateKey to be injected - like registering a CRUX ID
import com.crux.sdk.CruxClient;
import com.crux.sdk.model.*;
CruxClientInitConfig.Builder configBuilder = new CruxClientInitConfig.Builder()
.setWalletClientName("testwallet")
.setPrivateKey("6bd397dc89272e71165a0e7d197b288ed5b1e44e1928c25455506f1968f");
CruxClient cruxClient = new CruxClient(configBuilder, androidContextObject);
Read more about Initialisation of SDK Client
3. Start Using!
// Resolve any existing CRUX ID for a currency
cruxClient.resolveCurrencyAddressForCruxID('[email protected]','btc').then((address) => {
console.log(address);
})
// Create a new CRUX ID - [email protected]
cruxClient.registerCruxID('foo').then((result) => {
console.log(result);
// ID Will be owned by the injected private key
// New IDs take 6-8 confirmations in the Bitcoin network to confirm.
})
// You can check the status of the ID by asking the SDK for the CruxID State
cruxClient.getCruxIDState().then((cruxIDState) => {
console.log(cruxIDState);
})
// A registered ID allows you to associate cryptocurrency addresses
cruxClient.putAddressMap({
'btc': {
'addressHash':'1z2...42a'
},
'eth' {
'addressHash':'0x12z2...2d'
}
})
// Resolve any existing CRUX ID for a currency
cruxClient.resolveCurrencyAddressForCruxID(
"[email protected]", "xrp",
new CruxClientResponseHandler<CruxAddress>() {
@Override
public void onResponse(CruxAddress successResponse) {
System.out.println(successResponse);
}
@Override
public void onErrorResponse(CruxClientError failureResponse) {
System.out.println(failureResponse);
}
}
);
// Create a new CRUX ID - [email protected]
cruxClient.registerCruxID("mynewid",
new CruxClientResponseHandler<Void>() {
@Override
public void onResponse(Void successResponse) {
System.out.println(successResponse);
// ID Will be owned by the injected private key
// New IDs take 6-8 confirmations in the Bitcoin network to confirm.
}
@Override
public void onErrorResponse(CruxClientError failureResponse) {
}
}
);
// You can check the status of the ID by asking the SDK for the CruxID State
cruxClient.getCruxIDState(
new CruxClientResponseHandler<CruxIDState>() {
@Override
public void onResponse(CruxIDState successResponse) {
System.out.println(successResponse);
}
@Override
public void onErrorResponse(CruxClientError failureResponse) {
}
}
);
// A registered ID allows you to associate cryptocurrency addresses
private HashMap<String, CruxAddress> getCurrencyMap() {
HashMap<String, CruxAddress> currencyMap = new HashMap<String, CruxAddress>();
currencyMap.put("btc", new CruxAddress("1HX4KvtPdg9QUYwQE1kNqTAjmNaDG7w82V", null));
currencyMap.put("eth", new CruxAddress("0x0a2311594059b468c9897338b027c8782398b481", null));
currencyMap.put("tron", new CruxAddress("TG3iFaVvUs34SGpWq8RG9gnagDLTe1jdyz", null));
currencyMap.put("xrp", new CruxAddress("rpfKAA2Ezqoq5wWo3XENdLYdZ8YGziz48h", "7777"));
return currencyMap;
}
cruxClient.putAddressMap(getCurrencyMap(),
new CruxClientResponseHandler<CruxPutAddressMapSuccess>() {
@Override
public void onResponse(CruxPutAddressMapSuccess successResponse) {
System.out.println(successResponse);
}
@Override
public void onErrorResponse(CruxClientError failureResponse) {
}
}
);
Read more about SDK Integration Steps
Updated almost 5 years ago