Add codesandbox

This commit is contained in:
Jim Hamill
2025-04-07 05:55:06 +00:00
parent 5623b9b27c
commit afce97e34c
9 changed files with 866 additions and 29 deletions
+81
View File
@@ -0,0 +1,81 @@
---
aside: false
---
<script lang="ts" setup>
import CodeSandbox from '@theme/components/CodeSandbox.vue'
</script>
# Sandbox
We can include Code Sandboxes in our documentation.
This'll be very useful for:
1. Guides
2. Testing
## Primitives
The below is Address mess.
<!-- NOTE: It is absolutely crucial you leave a blank line before and after the backticks! Otherwise, you'll end up with errors.-->
<CodeSandbox>
```
const { Address } = await import('https://cdn.jsdelivr.net/npm/@xocash/stack@0.0.2-development.95/+esm');
const lockscriptHex = Address.from('bitcoincash:qr2084lauctzarqk20kqlhef8gyneqhceqy75wvw8q').toLockscriptHex();
console.log(lockscriptHex);
// Testing one new line
console.log({
someText: 'abc'
});
console.info('yep');
```
</CodeSandbox>
## Blockchain Connections
We can have more than one per page too. For example:
<!-- NOTE: It is absolutely crucial you leave a blank line before and after the backticks! Otherwise, you'll end up with errors.-->
<CodeSandbox>
```
const { BlockchainElectrum } = await import('https://cdn.jsdelivr.net/npm/@xocash/stack@0.0.2-development.95/+esm');
const blockchain = new BlockchainElectrum();
await blockchain.start();
const tx = await blockchain.fetchTransaction('a23bbd321067fd039da53f007b26f62591e58e6554b0488d83534c032dbca38b');
console.log('Transaction Hex', tx.toHex());
```
</CodeSandbox>
## Wallet Example
The below demonstrates instantiating a wallet.
<!-- NOTE: It is absolutely crucial you leave a blank line before and after the backticks! Otherwise, you'll end up with errors.-->
<CodeSandbox>
```
const { BlockchainElectrum, WalletP2PKH } = await import('https://cdn.jsdelivr.net/npm/@xocash/stack@0.0.2-development.95/+esm');
const wallet = WalletP2PKH.generateRandom({
blockchain: new BlockchainElectrum
});
const address = await wallet.getReceivingAddress();
console.log(address.toCashAddr());
```
</CodeSandbox>