Off-Exchange Settlement: Connect to Partners
Create a connection to a partner platform to trade assets custodied at BitGo. See the Guide.
-
You create a connection to a partner platform so you can trade assets custodied at BitGo Bank & Trust on their platform. You must first have an account on the partner's platform and generate an access token and read-only API key from that account. You can connect with multiple partners and have multiple connections to the same partner.
Prerequisites: Generate an access token and a read-only API key from your account on the partner platform.
// 1. Create Client Connection
export ACCESS_TOKEN="<YOUR_ACCESS_TOKEN>"
export ENTERPRISE_ID="<YOUR_ENTERPRISE_ID>"
curl -X POST \
https://app.bitgo-test.com/api/network/v1/enterprises/$ENTERPRISE_ID/clients/connections \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer $ACCESS_TOKEN' \
-d '{
"payload": "string",
"signature": "string",
"nonce": "string",
"partnerId": "string",
"name": "string",
"connectionKey": {
"schema": "token",
"connectionToken": "string"
}
}'
// 1. Create Client Connection
import { BitGoAPI } from '@bitgo/sdk-api';
import { Ecdsa } from '@bitgo/sdk-core/dist/src/bitgo/ecdsa';
import { createHash } from 'crypto';
import * as dotenv from 'dotenv';
const {
ACCESS_TOKEN,
ENTERPRISE_ID,
PARTNER_ID,
PARTNER_ACCESS_TOKEN,
PARTNER_SIGNING_SECRET,
} = process.env;
const bitgo = new BitGoAPI({
accessToken: ACCESS_TOKEN,
env: 'test', // Use 'prod' for the production environment
customRootURI: 'https://app.bitgo-test.com',
});
async function createClientConnection() {
if (!ENTERPRISE_ID || !PARTNER_ID || !PARTNER_ACCESS_TOKEN || !PARTNER_SIGNING_SECRET) {
console.error('Error: Missing required environment variables.');
return;
}
try {
console.log(`Fetching enterprise: ${ENTERPRISE_ID}`);
const enterprise = await bitgo.enterprises().get({ id: ENTERPRISE_ID });
console.log('Fetching signing payload from BitGo...');
const { payload, nonce } = await enterprise.clientConnections().getSigningPayload({ partnerId: PARTNER_ID });
console.log(`Received payload to sign: "${payload}"`);
console.log('Signing the payload locally...');
const ecdsa = new Ecdsa(PARTNER_SIGNING_SECRET);
const payloadHash = createHash('sha256').update(payload).digest();
const partnerSignature = ecdsa.sign(payloadHash).toString('hex');
console.log('Generated Signature:', partnerSignature);
const connectionParams = {
payload: payload, // The payload received from BitGo
signature: partnerSignature, // Your generated signature of that payload
nonce: nonce, // The nonce received from BitGo
partnerId: PARTNER_ID,
name: 'My New API Connection', // A friendly name for the connection
connectionKey: {
schema: 'token',
connectionToken: PARTNER_ACCESS_TOKEN,
},
};
console.log('Sending signed request to create connection...');
const connection = await enterprise.clientConnections().create(connectionParams);
console.log('Connection created successfully!');
console.dir(connection, { depth: null });
} catch (error) {
console.error('Failed to create connection:', error);
}
}
createClientConnection();
Response
// 1. Create Client Connection Response
{
"connection": {
"createdAt": "2019-08-24",
"updatedAt": "2019-08-24",
"partnersConnectionId": {},
"partnersClientId": {},
"initialized": true,
"id": "string",
"name": "string",
"clientId": "string",
"partnerId": "string",
"networkAccountId": "string",
"active": true,
"proof": "string",
"nonce": "string"
}
}