|
| 1 | +/** |
| 2 | + * Send a staking transaction from a multi-sig wallet at BitGo. |
| 3 | + * |
| 4 | + * Copyright 2022, BitGo, Inc. All Rights Reserved. |
| 5 | + */ |
| 6 | +const BitGoJS = require('bitgo'); |
| 7 | +const bitgo = new BitGoJS.BitGo({ env: 'test' }); |
| 8 | +const Promise = require('bluebird'); |
| 9 | +const coin = 'tada'; |
| 10 | +const basecoin = bitgo.coin(coin); |
| 11 | + |
| 12 | +// TODO: set your access token here |
| 13 | +const accessToken = ''; |
| 14 | +const walletId = '631b73c2bf01c90007f9154194486da3'; |
| 15 | + |
| 16 | +// TODO: set your passphrase here |
| 17 | +const walletPassphrase = null; |
| 18 | + |
| 19 | +Promise.coroutine(function *() { |
| 20 | + // generating address w/ same staking key and same payment key |
| 21 | + bitgo.authenticateWithAccessToken({ accessToken: accessToken }); |
| 22 | + yield bitgo.unlock({ otp: '000000', duration: 3600 }); |
| 23 | + const walletInstance = yield basecoin.wallets().get({ id: walletId }); |
| 24 | + |
| 25 | + const stakePoolKeyHash = 'fa1a5e1e70bc2fa7f60080b214f7bf5ab14c51da4b307a1a792c1714'; |
| 26 | + |
| 27 | + const whitelistedParams = { |
| 28 | + intent: { |
| 29 | + intentType: 'stake', |
| 30 | + stakingRequestId: '7265fe1ec9c304ad79f0-0000', |
| 31 | + poolKeyHash: stakePoolKeyHash, |
| 32 | + }, |
| 33 | + apiVersion: 'lite', |
| 34 | + preview: undefined, |
| 35 | + }; |
| 36 | + |
| 37 | + const unsignedTx = (yield bitgo |
| 38 | + .post(bitgo.url('/wallet/' + walletId + '/txrequests', 2)) |
| 39 | + .send(whitelistedParams) |
| 40 | + .result()); |
| 41 | + |
| 42 | + // sign tx |
| 43 | + const keychains = yield basecoin.keychains().getKeysForSigning({ wallet: walletInstance }); |
| 44 | + const signedStakingTransaction = yield walletInstance.signTransaction({ |
| 45 | + txPrebuild: unsignedTx, |
| 46 | + keychain: keychains[0], |
| 47 | + walletPassphrase: walletPassphrase, |
| 48 | + pubs: keychains.map((k) => k.pub), |
| 49 | + reqId: unsignedTx.txRequestId, |
| 50 | + }); |
| 51 | + |
| 52 | + // submit tx |
| 53 | + const submittedTx = yield bitgo |
| 54 | + .post(basecoin.url('/wallet/' + walletId + '/tx/send')) |
| 55 | + .send({ txRequestId: signedStakingTransaction.txRequestId }) |
| 56 | + .result(); |
| 57 | + |
| 58 | + console.log('New Transaction:', JSON.stringify(submittedTx, null, 4)); |
| 59 | + |
| 60 | +})(); |
0 commit comments