Skip to content

Commit dc8d3c2

Browse files
feat(root): enable passing apiKey for recovery on eth likes
- also added example for how to generate an unsigned tx Ticket: WP-5348
1 parent 1de8c2d commit dc8d3c2

File tree

20 files changed

+649
-123
lines changed

20 files changed

+649
-123
lines changed

examples/ts/eth/recover-eth.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* Recover ETH from a multi-sig wallet
3+
*
4+
* This script demonstrates how to generate an unsigned recovery transaction for a
5+
* Multi-Sig ETH wallet.
6+
*/
7+
8+
import { BitGo } from 'bitgo';
9+
import { Hteth } from '@bitgo/sdk-coin-eth';
10+
11+
// Set up BitGo object
12+
const bitgo = new BitGo({ env: 'test' }); // change to 'prod' for mainnet
13+
bitgo.register('hteth', Hteth.createInstance);
14+
15+
async function recoverEth() {
16+
try {
17+
// Use the recovery with API key for output
18+
const recovery = (await (bitgo.coin('hteth') as Hteth).recover({
19+
userKey: 'user-public-key',
20+
backupKey: 'backup-public-key',
21+
walletContractAddress: 'Address-of-your-multisig-wallet',
22+
recoveryDestination: 'Address-To-Recover-Funds-To',
23+
isUnsignedSweep: true,
24+
apiKey: 'Add Your Etherscan ApiKey here',
25+
})) as any;
26+
27+
// Print the recovery transaction hex
28+
console.log('Recovery transaction hex:');
29+
console.log(recovery.tx);
30+
31+
// Print additional information
32+
console.log('\nFull recovery object:', JSON.stringify(recovery, null, 2));
33+
34+
return recovery;
35+
} catch (e) {
36+
console.error('Error performing recovery:', e);
37+
throw e;
38+
}
39+
}
40+
41+
// Execute the recovery function
42+
recoverEth()
43+
.then(() => process.exit(0))
44+
.catch((e) => {
45+
console.error(e);
46+
process.exit(1);
47+
});

0 commit comments

Comments
 (0)