-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1282 from xchainjs/btc-taproot-example
Bitcoin taproot example
- Loading branch information
Showing
8 changed files
with
100 additions
and
0 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,9 @@ | ||
{ | ||
// These tasks will run in order when initializing your CodeSandbox project. | ||
"setupTasks": [ | ||
{ | ||
"name": "Install Dependencies", | ||
"command": "yarn install" | ||
} | ||
] | ||
} |
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,4 @@ | ||
{ | ||
"name": "Devcontainer", | ||
"image": "ghcr.io/codesandbox/devcontainers/typescript-node:latest" | ||
} |
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,2 @@ | ||
# xchainjs-bitcoin | ||
|
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,16 @@ | ||
# Bitcoin | ||
|
||
Bitcoin examples to show different use cases using its client | ||
|
||
## Examples | ||
|
||
### Address | ||
|
||
#### Get Taproot address by index | ||
|
||
Check out how you should get your Taproot account address at certain index in this [example](https://github.com/xchainjs/xchainjs-lib/blob/master/examples/solana/address.ts) or run it as | ||
|
||
```sh | ||
yarn taprootAddress phrase index | ||
``` | ||
|
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,21 @@ | ||
import { AddressFormat, Client, defaultBTCParams, tapRootDerivationPaths } from '@xchainjs/xchain-bitcoin' | ||
|
||
const main = async () => { | ||
const phrase = `${process.argv[2]}` | ||
const index = process.argv[3] ? Number(process.argv[3]) : 0 | ||
|
||
const client = new Client({ | ||
...defaultBTCParams, | ||
phrase, | ||
rootDerivationPaths: tapRootDerivationPaths, | ||
addressFormat: AddressFormat.P2TR, | ||
}) | ||
|
||
const address = await client.getAddressAsync(index) | ||
|
||
console.log(`Your Taproot account at index ${index} is ${address}`) | ||
} | ||
|
||
main() | ||
.then(() => process.exit(0)) | ||
.catch((err) => console.error(err)) |
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,21 @@ | ||
{ | ||
"name": "xchainjs-bitcoin", | ||
"private": true, | ||
"version": "0.0.1", | ||
"scripts": { | ||
"taprootAddress": "npx ts-node address-taproot.ts", | ||
"build": "tsc --noEmit" | ||
}, | ||
"description": "Examples using Bitcoin client", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@xchainjs/xchain-bitcoin": "workspace:*", | ||
"@xchainjs/xchain-util": "workspace:*" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "20.11.28", | ||
"ts-node": "10.9.2", | ||
"typescript": "^5.0.4" | ||
} | ||
} |
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,15 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"target": "es5", | ||
"noEmitOnError": true, | ||
"resolveJsonModule": true, | ||
"esModuleInterop": true, | ||
"lib": [ | ||
"es6", | ||
"dom", | ||
"es2016", | ||
"es2017" | ||
] | ||
} | ||
} |
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