Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(root): add sui custom tx script #3989

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/js/sui/custom-tx/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
16.18.0
59 changes: 59 additions & 0 deletions examples/js/sui/custom-tx/custom-tx.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 coin = 'tsui';
const basecoin = bitgo.coin(coin);

// TODO: set your access token here
const walletId = '<wallet-id>';
const accessToken = '<access-token>';

// TODO: set your passphrase here
const walletPassphrase = '<wallet-passphrase>';

// TODO: set tx hex here
const base64TxHex = '<base64-tx-hex>';

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));
17 changes: 17 additions & 0 deletions examples/js/sui/custom-tx/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
Loading