-
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.
feat(sdk): support bulk minting with pointers (#121)
* feat(sdk): support bulk minting with pointers * export types * add example to inscribeV2
- Loading branch information
Showing
12 changed files
with
721 additions
and
3 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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { bulkMintFromCollection, InscriberV2, JsonRpcDatasource } from "@sadoprotocol/ordit-sdk" | ||
import { Inscriber, Ordit } from "@sadoprotocol/ordit-sdk" | ||
|
||
const MNEMONIC = "<mnemonic>" | ||
const network = "testnet" | ||
const datasource = new JsonRpcDatasource({ network }) | ||
|
||
async function main() { | ||
// init wallet | ||
const serverWallet = new Ordit({ | ||
bip39: MNEMONIC, | ||
network | ||
}) | ||
|
||
serverWallet.setDefaultAddress("taproot") | ||
|
||
const ordinalReceiverAddress = "<address>" | ||
const paymentRefundAddress = "<address>" | ||
|
||
// new inscription tx | ||
const transaction = await bulkMintFromCollection({ | ||
address: serverWallet.selectedAddress, | ||
publicKey: serverWallet.publicKey, | ||
publisherAddress: serverWallet.selectedAddress, | ||
collectionGenesis: "df91a6386fb9b55bd754d6ec49e97e1be4c80ac49e4242ff773634e4c23cc427", | ||
changeAddress: paymentRefundAddress, | ||
feeRate: 10, | ||
outputs: [{ address: ordinalReceiverAddress, value: 999 }], | ||
network, | ||
datasource, | ||
taptreeVersion: "3", | ||
inscriptions: [ | ||
{ | ||
mediaContent: "Hello World", | ||
mediaType: "text/plain", | ||
postage: 1000, | ||
nonce: 0, | ||
receiverAddress: ordinalReceiverAddress, | ||
iid: "testhello", | ||
signature: "sig" | ||
} | ||
] | ||
}) | ||
|
||
// generate deposit address and fee for inscription | ||
const revealed = await transaction.generateCommit() | ||
console.log(revealed) // deposit revealFee to address | ||
|
||
// confirm if deposit address has been funded | ||
const ready = await transaction.isReady() | ||
|
||
if (ready || transaction.ready) { | ||
// build transaction | ||
await transaction.build() | ||
|
||
// sign transaction | ||
const signedTxHex = serverWallet.signPsbt(transaction.toHex(), { isRevealTx: true }) | ||
|
||
// Broadcast transaction | ||
const tx = await datasource.relay({ hex: signedTxHex }) | ||
console.log(tx) | ||
} | ||
} | ||
|
||
main() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { splitInscriptionId } from "../utils" | ||
|
||
export function trimTrailingZeroBytes(buffer: Buffer): Buffer { | ||
let trimmedBuffer = buffer | ||
for (let i = buffer.length - 1; i >= 0; i--) { | ||
// find the first non-zero byte | ||
if (buffer[i] !== 0) { | ||
trimmedBuffer = buffer.subarray(0, i + 1) | ||
break | ||
} | ||
} | ||
return trimmedBuffer | ||
} | ||
|
||
export function encodePointer(num: number | string | bigint): Buffer { | ||
const buffer = Buffer.allocUnsafe(8) | ||
buffer.writeBigUInt64LE(BigInt(num)) | ||
return trimTrailingZeroBytes(buffer) | ||
} | ||
|
||
export function encodeTag(tag: number): Buffer { | ||
let tagInHex = tag.toString(16) | ||
// ensure even length or Buffer.from will remove odd length bytes | ||
if (tagInHex.length % 2 !== 0) { | ||
tagInHex = "0" + tagInHex | ||
} | ||
return Buffer.from(tagInHex, "hex") | ||
} | ||
|
||
function reverseBufferByteChunks(src: Buffer): Buffer { | ||
const buffer = Buffer.from(src) | ||
return buffer.reverse() | ||
} | ||
|
||
export function encodeInscriptionId(inscriptionId: string): Buffer { | ||
const { txId, index } = splitInscriptionId(inscriptionId) | ||
|
||
// reverse txId byte | ||
const txidBuffer = Buffer.from(txId, "hex") | ||
const reversedTxIdBuffer = reverseBufferByteChunks(txidBuffer) | ||
|
||
// Convert index to little-endian, max 4 bytes | ||
const indexBuffer = Buffer.alloc(4) | ||
indexBuffer.writeUInt32LE(index) | ||
|
||
// Trim trailing zero bytes | ||
const trimmedIndexBuffer = trimTrailingZeroBytes(indexBuffer) | ||
|
||
return Buffer.concat([reversedTxIdBuffer, trimmedIndexBuffer]) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
export interface MetaParams { | ||
collectionGenesis: string | ||
iid: string | ||
publisher: string | ||
nonce: number | ||
receiverAddress: string | ||
signature?: string | ||
} | ||
|
||
export function buildMeta({ collectionGenesis, iid, publisher, nonce, receiverAddress, signature }: MetaParams) { | ||
return { | ||
p: "vord", | ||
v: 1, | ||
ty: "insc", | ||
col: collectionGenesis, | ||
iid, | ||
publ: publisher, | ||
nonce: nonce, | ||
minter: receiverAddress, | ||
sig: signature | ||
} | ||
} |
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.