-
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
feat(bitgo): add ada pledging example
- Loading branch information
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
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 @@ | ||
const BitGoJS = require('bitgo'); | ||
const bitgo = new BitGoJS.BitGo({ env: 'test' }); | ||
const Promise = require('bluebird'); | ||
const coin = 'tada'; | ||
const basecoin = bitgo.coin(coin); | ||
|
||
// TODO: set your access token here | ||
const accessToken = ''; | ||
const walletId = '649b57342f95fd00075b0ab393822a33'; | ||
|
||
// TODO: set your passphrase here | ||
const walletPassphrase = null; | ||
|
||
// TODO: set pledging inputs | ||
const pledgingRawTxHex = ''; | ||
const pledgingNodePubKey = ''; | ||
const pledgingNodeKeySignature = ''; | ||
|
||
Promise.coroutine(function *() { | ||
// generating address w/ same staking key and same payment key | ||
bitgo.authenticateWithAccessToken({ accessToken: accessToken }); | ||
yield bitgo.unlock({ otp: '000000', duration: 3600 }); | ||
const walletInstance = yield basecoin.wallets().get({ id: walletId }); | ||
|
||
const whitelistedParams = { | ||
intent: { | ||
intentType: 'pledge', | ||
rawTx: pledgingRawTxHex, | ||
nodePublicKey: pledgingNodePubKey, | ||
nodeKeySignature: pledgingNodeKeySignature, | ||
}, | ||
apiVersion: 'lite', | ||
preview: undefined, | ||
}; | ||
|
||
const unsignedTx = (yield bitgo | ||
.post(bitgo.url('/wallet/' + walletId + '/txrequests', 2)) | ||
.send(whitelistedParams) | ||
.result()); | ||
|
||
// sign tx | ||
const keychains = yield basecoin.keychains().getKeysForSigning({ wallet: walletInstance }); | ||
const signedStakingTransaction = yield walletInstance.signTransaction({ | ||
txPrebuild: unsignedTx, | ||
keychain: keychains[0], | ||
walletPassphrase: walletPassphrase, | ||
pubs: keychains.map((k) => k.pub), | ||
reqId: unsignedTx.txRequestId, | ||
}); | ||
|
||
// submit tx | ||
const submittedTx = yield bitgo | ||
.post(basecoin.url('/wallet/' + walletId + '/tx/send')) | ||
.send({ txRequestId: signedStakingTransaction.txRequestId }) | ||
.result(); | ||
|
||
console.log('New Transaction:', JSON.stringify(submittedTx, null, 4)); | ||
|
||
})(); |