diff --git a/examples/js/sui/custom-tx/.nvmrc b/examples/js/sui/custom-tx/.nvmrc new file mode 100644 index 0000000000..94f5f26dcb --- /dev/null +++ b/examples/js/sui/custom-tx/.nvmrc @@ -0,0 +1 @@ +16.18.0 diff --git a/examples/js/sui/custom-tx/custom-tx.js b/examples/js/sui/custom-tx/custom-tx.js new file mode 100644 index 0000000000..cf0546b698 --- /dev/null +++ b/examples/js/sui/custom-tx/custom-tx.js @@ -0,0 +1,59 @@ +const BitGoJS = require('bitgo'); +const bitgo = new BitGoJS.BitGo({ env: 'test' }); +const coin = 'tsui'; +const basecoin = bitgo.coin(coin); + +// TODO: set your access token here +const walletId = ''; +const accessToken = ''; + +// TODO: set your passphrase here +const walletPassphrase = ''; + +// TODO: set tx hex here +const base64TxHex = ''; + +async function submitCustomTx() { + // (Optional) unlock if needed + bitgo.authenticateWithAccessToken({ accessToken: accessToken }); + await bitgo.unlock({ otp: '000000', duration: 3600 }); + const walletInstance = await basecoin.wallets().get({ id: walletId }); + + console.log('Wallet ID:', walletInstance.id()); + + const whitelistedParams = { + intent: { + intentType: 'customTx', + rawTx: base64TxHex, + }, + apiVersion: 'full', // TODO: change to 'lite' for hot wallet + }; + + const unsignedTx = await bitgo + .post(bitgo.url('/wallet/' + walletId + '/txrequests', 2)) + .send(whitelistedParams) + .result(); + + console.log('Unsigned Transaction:', JSON.stringify(unsignedTx, null, 4)); + + // TODO: uncomment below for hot wallet only + // sign tx + // const keychains = await basecoin.keychains().getKeysForSigning({ wallet: walletInstance }); + // const signedTx = await walletInstance.signTransaction({ + // txPrebuild: unsignedTx, + // keychain: keychains[0], + // pubs: keychains.map((k) => k.pub), + // reqId: unsignedTx.txRequestId, + // walletPassphrase: walletPassphrase, + // }); + + // submit tx + // const submittedTx = await bitgo + // .post(basecoin.url('/wallet/' + walletId + '/tx/send')) + // .send({ txRequestId: signedTx.txRequestId }) + // .result(); + + // console.log('Submitted transaction:', JSON.stringify(submittedTx, null, 4)); +} + +submitCustomTx().catch((e) => console.error(e)); diff --git a/examples/js/sui/custom-tx/package.json b/examples/js/sui/custom-tx/package.json new file mode 100644 index 0000000000..e38919f5d4 --- /dev/null +++ b/examples/js/sui/custom-tx/package.json @@ -0,0 +1,17 @@ +{ + "name": "custom-tx", + "version": "1.0.0", + "description": "Examples to initiate SUI custom tx", + "main": "index.js", + "scripts": { + "customTx": "node custom-tx.js" + }, + "author": "", + "license": "ISC", + "dependencies": { + "bitgo": "^19.18.0" + }, + "devDependencies": { + "prettier": "^3.0.3" + } +}