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

Examples of ordinals #4946

Merged
merged 4 commits into from
Sep 26, 2024
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
9 changes: 0 additions & 9 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,6 @@ In this directory, you can find examples on how to use the BitGoJS SDK with Type
- [Enable Token](./ts/algo/enable-token.ts)
- [Transaction with emergency param](./ts/algo/transaction-with-emergency-param.ts)

### Bitcoin Lightning (BTC)

- [Check Lightning Balance](./ts/btc/check-lightning-balance.ts)
- [Create Lightning Invoice](./ts/btc/create-lightning-invoice.ts)
- [Withdraw Lightning Balance](./ts/btc/withdraw-lightning-balance.ts)
- [Make Lightning Deposit](./ts/btc/make-lightning-deposit.ts)
- [Make Lightning Payment](./ts/btc/make-lightning-payment.ts)
- [Pay LNURL Request](./ts/btc/pay-lnurl-request.ts)

### Ethereum (ETH)

- [Create Wallet Address](./ts/eth/create-wallet-address.ts)
Expand Down
50 changes: 50 additions & 0 deletions examples/ts/btc/ordinals/move-individual-ordinal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* Transfer an individual ordinal from one address to another
*
* Copyright 2024 BitGo, Inc. All Rights Reserved.
*/

const BitGoJS = require('bitgo');

// change this to env: 'prod' when you are ready for production
const env = 'test';
// change coin to 'btc' when working with production
const coin = env === 'test' ? 'tbtc' : 'btc';

const bitgo = new BitGoJS.BitGo({ env });

// set your access token and walletPassphrase here
const accessToken = '';
const walletPassphrase = '';

// set your wallet ID here
const walletId = '';

// The location of the ordinal you want to send {txid}:{vout}:{offset}
// Background about how ordinals work here: https://docs.ordinals.com/overview.html
const satPoint = '';

// set where you are sending the ordinal
const recipient = '';

// set the fee rate for the transaction in Satoshis per KB
const feeRateSatKb = 1000;

async function transferIndividualOrdinal() {
// Authenticate and get wallet
await bitgo.authenticateWithAccessToken({ accessToken });
const wallet = await bitgo.coin(coin).wallets().get({ id: walletId });

// Instantiate the transaction builder that will be used to send the particular ordinal
// We need to use this specific transaction builder so that we are safely extracting the exact ordinal.
const inscriptionBuilder = bitgo.coin(coin).getInscriptionBuilder(wallet);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have much ragrets calling this getInscriptionBuilder. smh to my past self.


// Build the transaction to send the ordinal
// Note that you can configure the structure of the transaction by passing in additional parameters
const buildResult = await inscriptionBuilder.prepareTransfer(satPoint, recipient, feeRateSatKb, {});

const sent = await inscriptionBuilder.signAndSendTransfer(walletPassphrase, buildResult);
console.log('sent ' + JSON.stringify(sent, null, 2));
}

transferIndividualOrdinal().catch(console.error);
57 changes: 57 additions & 0 deletions examples/ts/reserve-unspents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* Manage unspent reservations on your wallet
*
* Copyright 2024 BitGo, Inc. All Rights Reserved.
*/

const BitGoJS = require('modules/bitgo');

// change this to env: 'prod' when you are ready for production
const env = 'test';
// change coin to 'btc' when working with production
const coin = env === 'test' ? 'tbtc' : 'btc';

const bitgo = new BitGoJS.BitGo({ env });

// set your access token here
const accessToken = '';

// set the unspent IDs to manage the reservations of
const unspentIds = ['', ''];

// set the expire time for the reservation (use 'never' to freeze)
const expireTime = '';

async function createUnspentReservation() {
Dismissed Show dismissed Hide dismissed
bitgo.authenticateWithAccessToken({ accessToken });
const wallet = await bitgo.coin(coin).wallets().get({ id: walletId });

const reserveResult = await wallet.manageUnspentReservations({
create: { unspentIds, expireTime: 'never' },
});
console.log('reserved ' + JSON.stringify(reserveResult, null, 2));
}

async function modifyUnspentReservation() {
Dismissed Show dismissed Hide dismissed
bitgo.authenticateWithAccessToken({ accessToken });
const wallet = await bitgo.coin(coin).wallets().get({ id: walletId });

const reserveResult = await wallet.manageUnspentReservations({
modify: { unspentIds, changes: { expireTime } },
});
console.log('modified ' + JSON.stringify(reserveResult, null, 2));
}

async function releaseUnspentReservation() {
Dismissed Show dismissed Hide dismissed
bitgo.authenticateWithAccessToken({ accessToken });
const wallet = await bitgo.coin(coin).wallets().get({ id: walletId });

const reserveResult = await wallet.manageUnspentReservations({
delete: { id: unspentIds[0] },
});
console.log('released ' + JSON.stringify(reserveResult, null, 2));
}

// createUnspentReservation().catch(console.error);
// modifyUnspentReservation().catch(console.error);
// releaseUnspentReservation().catch(console.error);
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export interface IInscriptionBuilder {
cosigner,
inscriptionConstraints,
changeAddressType,
txFormat,
}: {
signer: utxolib.bitgo.KeyName;
cosigner: utxolib.bitgo.KeyName;
Expand All @@ -65,6 +66,7 @@ export interface IInscriptionBuilder {
maxInscriptionOutput?: bigint;
};
changeAddressType: utxolib.bitgo.outputScripts.ScriptType2Of3;
txFormat?: 'psbt' | 'legacy';
}
): Promise<PrebuildTransactionResult>;

Expand Down
Loading