Skip to content

Commit

Permalink
Merge pull request #3700 from BitGo/EA-710
Browse files Browse the repository at this point in the history
feat(bitgo): add ada pledging example
  • Loading branch information
evanzbitgo authored Jun 29, 2023
2 parents 084ab73 + 2102bf3 commit 6fe6055
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions examples/js/ada/send-pledge-transaction.js
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));

})();

0 comments on commit 6fe6055

Please sign in to comment.