-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: initial integration w/ PSBTBuilder * refactor: remove unncessary try..catch block * refactor: update import path * refactor: bind input payload to derived class member * fix: use await for async fn * fix: ignore precalculated postage also, reduce usage of extra variables * refactor!: make props required * chore: ignore dist directory * refactor: enable `inscriberMode` in OrdTransaction * chore: exclude nod_modules & dist dir from vscode search * feat: rename `OrdTransaction` to `Inscriber` also, deprecate OrdTransaction class * refactor: rename arg options type * refactor: replace deprecated class name w/ new one * refactor: rename file * refactor!: remove defaults, rename & rearrange args * refactor: remove unwanted getter * feat!: remove support for change in Inscriber Not possible to know what original utxo sats would be to calculate change * feat: add preview mode flag and restrict specific operation * refactor: move duplicate code to fn * refactor: update collection publish & mint example * refactor: update create-psbt example * chore: deprecate irrelevant methods from Ordit class * refactor: update property name * refactor: update create collection and mint example * refactor: update publish collection example
- Loading branch information
1 parent
7c78e61
commit 4b0e73a
Showing
10 changed files
with
395 additions
and
452 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 |
---|---|---|
|
@@ -61,3 +61,5 @@ logs | |
*.log | ||
npm-debug.log* | ||
lerna-debug.log* | ||
|
||
**/dist |
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
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 |
---|---|---|
@@ -1,28 +1,46 @@ | ||
import { Ordit } from "@sadoprotocol/ordit-sdk"; | ||
import { Ordit, mintFromCollection, publishCollection } from "@sadoprotocol/ordit-sdk"; | ||
|
||
const WORDS = "<MNEMONIC PHRASE>"; | ||
const mnemonic = "<MNEMONIC PHRASE>"; | ||
const network = "testnet" | ||
|
||
// User is the party who would mint the assets from a collection | ||
const userWallet = new Ordit({ | ||
bip39: mnemonic, | ||
network | ||
}); | ||
|
||
// Publisher is the marketplace and any party owning the on-chain collection | ||
const publisherWallet = new Ordit({ | ||
bip39: mnemonic, | ||
network | ||
}); | ||
|
||
// set default address types for both wallets | ||
userWallet.setDefaultAddress("taproot"); | ||
publisherWallet.setDefaultAddress("nested-segwit"); | ||
|
||
async function publish() { | ||
// Load wallet | ||
const wallet = new Ordit({ | ||
bip39: WORDS, | ||
network: "testnet" | ||
}); | ||
const getPublisherLegacyAddress = () => { | ||
publisherWallet.setDefaultAddress("legacy") | ||
const legacyAddress = publisherWallet.selectedAddress | ||
publisherWallet.setDefaultAddress("nested-segwit") // switch back to default | ||
|
||
//set default taproot | ||
wallet.setDefaultAddress("taproot"); | ||
return legacyAddress | ||
} | ||
|
||
//publish | ||
const transaction = await Ordit.collection.publish({ | ||
const transaction = await publishCollection({ | ||
network, | ||
feeRate: 2, | ||
title: "Collection Name", | ||
description: "Lorem ipsum something else", | ||
slug: "collection-name", | ||
creator: { | ||
address: wallet.selectedAddress, | ||
address: publisherWallet.selectedAddress, | ||
email: "[email protected]", | ||
name: "Your Name" | ||
}, | ||
publishers: ["<publisher-legacy-address>"], | ||
publishers: [getPublisherLegacyAddress()], | ||
inscriptions: [ | ||
{ | ||
iid: "el-01", | ||
|
@@ -36,93 +54,73 @@ async function publish() { | |
} | ||
], | ||
url: "https://example.com", | ||
publicKey: wallet.publicKey, | ||
destination: wallet.selectedAddress, | ||
changeAddress: wallet.selectedAddress, | ||
publicKey: publisherWallet.publicKey, | ||
destination: publisherWallet.selectedAddress, | ||
changeAddress: publisherWallet.selectedAddress, | ||
postage: 1000, | ||
mediaContent: 'Collection Name', // this will be inscribed on-chain as primary content | ||
mediaType: "text/plain" | ||
}); | ||
|
||
const depositDetails = transaction.generateCommit(); | ||
const depositDetails = await transaction.generateCommit(); | ||
console.log(depositDetails); | ||
|
||
// // confirm if deposit address has been funded | ||
// confirm if deposit address has been funded | ||
const ready = await transaction.isReady(); //- true/false | ||
|
||
if (ready || transaction.ready) { | ||
// build transaction | ||
transaction.build(); | ||
await transaction.build(); | ||
|
||
// sign transaction | ||
const psbtHex = transaction.toHex(); | ||
const sig = wallet.signPsbt(psbtHex, { isRevealTx: true }); | ||
// console.log(JSON.stringify(sig, null, 2)) | ||
const signedTx = publisherWallet.signPsbt(transaction.toHex(), { isRevealTx: true }); | ||
|
||
// Broadcast transaction | ||
const submittedTx = await wallet.relayTx(sig, "testnet"); | ||
console.log(submittedTx); | ||
//{"txid": "<TX_ID>"} | ||
const txId = await publisherWallet.relayTx(signedTx, network); | ||
console.log({ txId }); | ||
} | ||
} | ||
|
||
async function mint() { | ||
// Load wallet | ||
const userWallet = new Ordit({ | ||
bip39: "<MNEMONIC PHRASE>", | ||
network: "testnet" | ||
}); | ||
|
||
const pubWallet = new Ordit({ | ||
bip39: "<MNEMONIC PHRASE>", | ||
network: "testnet" | ||
}); | ||
|
||
//set default taproot | ||
userWallet.setDefaultAddress("taproot"); | ||
// pubWallet.setDefaultAddress("taproot"); | ||
|
||
// details of mint | ||
const col = "04a0d2c4215607f2a16a5a458d0bd8e0528de0b7990bd9d52659d7d5c6263a54:0"; | ||
const sigMsg = `${col} el-01 1`; // COLLECTION_OUT INSCRIPTION_IID NONCE | ||
const sig = pubWallet.signMessage(sigMsg); | ||
|
||
pubWallet.setDefaultAddress("taproot"); | ||
//publish | ||
const transaction = await Ordit.collection.mint({ | ||
collectionOutpoint: col, | ||
// replace this w/ the resulting txId:index of above publish() fn | ||
const collectionId = ""; | ||
const message = `${collectionId.split(":")[0]} el-01 1`; // COLLECTION_OUT INSCRIPTION_IID NONCE | ||
const signature = publisherWallet.signMessage(message); | ||
|
||
// publish | ||
const transaction = await mintFromCollection({ | ||
network, | ||
collectionOutpoint: collectionId, | ||
inscriptionIid: "el-01", | ||
nonce: 1, | ||
publisherIndex: 0, | ||
signature: sig, | ||
signature, | ||
publicKey: userWallet.publicKey, | ||
destination: userWallet.selectedAddress, | ||
changeAddress: userWallet.selectedAddress, | ||
postage: 1000, | ||
feeRate: 2, | ||
mediaContent: 'Sample content', | ||
mediaType: "text/plain", | ||
outs: [{address: 'tb1pk6yxhcwzzjg9gwsumnlrh3l9q3ajxk657e7kqwmwpd8mklmnmehsrn3hu2', value: 1000}] | ||
outputs: [], | ||
}); | ||
|
||
const depositDetails = transaction.generateCommit(); | ||
const depositDetails = await transaction.generateCommit(); | ||
console.log(depositDetails); | ||
|
||
// // confirm if deposit address has been funded | ||
// confirm if deposit address has been funded | ||
const ready = await transaction.isReady(); //- true/false | ||
|
||
if (ready || transaction.ready) { | ||
// build transaction | ||
transaction.build(); | ||
await transaction.build(); | ||
|
||
// sign transaction | ||
const psbtHex = transaction.toHex(); | ||
const sig = userWallet.signPsbt(psbtHex, { isRevealTx: true }); | ||
// console.log(JSON.stringify(sig, null, 2)) | ||
const signedTx = userWallet.signPsbt(transaction.toHex(), { isRevealTx: true }); | ||
|
||
// Broadcast transaction | ||
const submittedTx = await userWallet.relayTx(sig, "testnet"); | ||
console.log(submittedTx); | ||
//{"txid": "<TX_ID>"} | ||
const txId = await userWallet.relayTx(signedTx, network); | ||
console.log({ txId }); | ||
} | ||
} | ||
|
||
publish(); | ||
mint(); | ||
publish(); // comment this after collection is created | ||
// mint(); // uncomment this after collection is created on chain using publish() |
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
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
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
Oops, something went wrong.