-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
chore(bitgo): add trx smc consolidation example
- Loading branch information
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import axios from 'axios'; | ||
|
||
// TODO: set your local external signer url | ||
const LOCAL_EXTERNAL_SIGNER_URL = 'http://localhost:3080'; | ||
// TODO: set your access token here | ||
// You can get this from User Settings > Developer Options > Add Access Token | ||
const accessToken = ''; | ||
// TODO: set your wallet id | ||
const walletId = ''; | ||
const options = { | ||
headers: { | ||
Authorization: `Bearer ${accessToken}`, | ||
'Content-Type': 'application/json', | ||
}, | ||
}; | ||
|
||
async function consolidateReceiveAddresses(coin: string, receiveAddresses?: string[]) { | ||
const consolidateUrl = `${LOCAL_EXTERNAL_SIGNER_URL}/api/v2/${coin}/wallet/${walletId}/consolidateAccount`; | ||
const response = receiveAddresses | ||
? await axios.post( | ||
consolidateUrl, | ||
{ | ||
consolidateAddresses: receiveAddresses, | ||
}, | ||
options | ||
) | ||
: await axios.post(consolidateUrl, {}, options); | ||
|
||
const txids = response.data.success.map((item) => item.txid); | ||
console.info(`Succeeded to consolidate receive addresses. Txids: ${txids}`); | ||
} | ||
|
||
async function main() { | ||
try { | ||
const unlockUrl = `${LOCAL_EXTERNAL_SIGNER_URL}/api/v2/user/unlock`; | ||
const unlockData = { | ||
duration: 3600, | ||
otp: '000000', | ||
}; | ||
await axios.post(unlockUrl, unlockData, options); | ||
console.info(`Succeeded to unlock with OTP`); | ||
|
||
// Consolidate native token at specific receive addresses | ||
await consolidateReceiveAddresses('ttrx', ['receiveAddress1']); | ||
|
||
// Consolidate TRC20 token at specific receive addresses | ||
await consolidateReceiveAddresses('ttrx:usdt', ['receiveAddress1', 'receiveAddress2']); | ||
|
||
// Consolidate native token at all receive addresses | ||
await consolidateReceiveAddresses('ttrx'); | ||
|
||
// Consolidate TRC20 token at all receive addresses | ||
await consolidateReceiveAddresses('ttrx:usdt'); | ||
} catch (e) { | ||
console.error(`Failed to consolidate receive addresses error: ${e.message}`); | ||
} | ||
} | ||
|
||
main().catch((e) => console.error(e)); |