Skip to content

Commit

Permalink
feat: add brc20 examples
Browse files Browse the repository at this point in the history
  • Loading branch information
iamcrazycoder committed Oct 31, 2023
1 parent d2df96e commit c5f7746
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 1 deletion.
33 changes: 33 additions & 0 deletions examples/node/brc-20-deploy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { BRC20Deploy, JsonRpcDatasource, Ordit } from '@sadoprotocol/ordit-sdk'

const network = 'regtest'
const wallet = new Ordit({
bip39: '<mnemonic>',
network
})
wallet.setDefaultAddress('taproot')
const datasource = new JsonRpcDatasource({ network })

async function main() {
const tx = new BRC20Deploy({
address: wallet.selectedAddress,
pubKey: wallet.publicKey,
destinationAddress: wallet.selectedAddress,
feeRate: 2,
network: 'regtest',
tick: 'TEST',
supply: 1000000000,
limit: 100,
})

const revealData = await tx.reveal()
console.log({ revealData })

const hex = await tx.deploy()
const signedTxHex = wallet.signPsbt(hex, { isRevealTx: true })
const txId = await datasource.relay({ hex: signedTxHex })

console.log({ txId })
}

main()
34 changes: 34 additions & 0 deletions examples/node/brc-20-mint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { BRC20Mint, JsonRpcDatasource, Ordit } from '@sadoprotocol/ordit-sdk'

const network = 'regtest'
const wallet = new Ordit({
bip39: '<mnemonic>',
network
})
wallet.setDefaultAddress('taproot')
const datasource = new JsonRpcDatasource({ network })

async function main() {
const tx = new BRC20Mint({
address: wallet.selectedAddress,
pubKey: wallet.publicKey,
destinationAddress: wallet.selectedAddress,
feeRate: 2,
network,
tick: 'TEST',
amount: 100
})

const revealData = await tx.reveal()
console.log({ revealData })

const hex = await tx.mint()
if(!hex) return

const signedTxHex = wallet.signPsbt(hex, { isRevealTx: true })
const txId = await datasource.relay({ hex: signedTxHex })

console.log({ txId })
}

main()
38 changes: 38 additions & 0 deletions examples/node/brc-20-transfer-executor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { BRC20TransferExecutor, JsonRpcDatasource, Ordit } from '@sadoprotocol/ordit-sdk'

const network = 'regtest'
const wallet = new Ordit({
bip39: '<mnemonic>',
network
})

const destWallet = new Ordit({
bip39: '<mnemonic>',
network
})

wallet.setDefaultAddress('taproot')
destWallet.setDefaultAddress('taproot')
const datasource = new JsonRpcDatasource({ network })
const destinationAddress = wallet.selectedAddress

async function main() {
const tx = new BRC20TransferExecutor({
address: wallet.selectedAddress,
pubKey: wallet.publicKey,
destinationAddress,
feeRate: 2,
network,
tick: 'TEST',
amount: 10
})

const hex = await tx.transfer()
if(hex) {
const signedTxHex = wallet.signPsbt(hex, { isRevealTx: true })
const txId = await datasource.relay({ hex: signedTxHex })
console.log({ txId })
}
}

main()
34 changes: 34 additions & 0 deletions examples/node/brc-20-transfer-generator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { BRC20TransferGenerator, JsonRpcDatasource, Ordit } from '@sadoprotocol/ordit-sdk'

const network = 'regtest'
const wallet = new Ordit({
bip39: '<mnemonic>',
network
})
wallet.setDefaultAddress('taproot')
const datasource = new JsonRpcDatasource({ network })

async function main() {
const tx = new BRC20TransferGenerator({
address: wallet.selectedAddress,
pubKey: wallet.publicKey,
feeRate: 3,
network,
tick: 'TEST',
amount: 10
})

const revealData = await tx.reveal()
console.log({ revealData })

// generate transfer inscription
const hex = await tx.generate()

if(hex) {
const signedTxHex = wallet.signPsbt(hex, { isRevealTx: true })
const txId = await datasource.relay({ hex: signedTxHex })
console.log({ txId })
}
}

main()
6 changes: 5 additions & 1 deletion examples/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
"instant-buy": "node instant-buy",
"publish-collection": "node collections",
"build-psbt": "node build-psbt",
"split-utxo": "node split-utxo"
"split-utxo": "node split-utxo",
"brc20-deploy": "node brc-20-deploy",
"brc20-mint": "node brc-20-mint",
"brc20-transfer-generator": "node brc-20-transfer-generator",
"brc20-transfer-executor": "node brc-20-transfer-executor"
},
"author": "",
"license": "ISC",
Expand Down

0 comments on commit c5f7746

Please sign in to comment.