Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add create inscription sample & testnet4 #201

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { SendInscription } from './components/sendInscriptions';
import AddressDisplay from './components/AddressDisplay';
import { GetAddresses } from './components/bitcoin/GetAddresses.tsx';
import { SendBtc } from './components/bitcoin/SendBtc';
import { CreateInscription } from './components/createInscription/index.tsx';
import EtchRunes from './components/EtchRunes';
import MintRunes from './components/MintRunes';
import { MobileUniversalLink } from './components/mobile/universalLink.tsx';
Expand Down Expand Up @@ -303,6 +304,7 @@ const BitcoinMethods = () => {
<SignMessage addresses={[...btcAddressInfo]} />
<SendBtc network={network} />
<SendInscription network={network} />
<CreateInscription network={network} />
<TransferRunes network={network} />
<GetBtcBalance />
<GetRunesBalance />
Expand Down
6 changes: 6 additions & 0 deletions example/src/components/EtchRunes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ export const EtchRunes = ({ addresses, network }: Props) => {
[BitcoinNetworkType.Testnet]: '/testnet',
[BitcoinNetworkType.Signet]: '/signet',
};

if (network === BitcoinNetworkType.Testnet4 || network === BitcoinNetworkType.Regtest) {
console.error('Network not supported for etching runes');
return;
}

const fundTxLink = `https://mempool.space${networkPath[network]}/tx/${fundTxId}`;

return (
Expand Down
4 changes: 4 additions & 0 deletions example/src/components/MintRunes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ export const MintRunes = ({ addresses, network }: Props) => {
[BitcoinNetworkType.Testnet]: '/testnet',
[BitcoinNetworkType.Signet]: '/signet',
};
if (network === BitcoinNetworkType.Testnet4 || network === BitcoinNetworkType.Regtest) {
console.error('Network not supported for etching runes');
return;
}
const fundTxLink = `https://mempool.space${networkPath[network]}/tx/${fundTxId}`;

return (
Expand Down
6 changes: 4 additions & 2 deletions example/src/components/NetworkSelector/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ export const NetworkSelector = ({ network, setNetwork }: Props) => {
const onNetworkChange = () => {
const newNetwork =
network === BitcoinNetworkType.Mainnet
? BitcoinNetworkType.Testnet
: network === BitcoinNetworkType.Testnet
? BitcoinNetworkType.Testnet4
: network === BitcoinNetworkType.Testnet4
? BitcoinNetworkType.Signet
: network === BitcoinNetworkType.Signet
? BitcoinNetworkType.Testnet
: BitcoinNetworkType.Mainnet;
setNetwork(newNetwork);
};
Expand Down
6 changes: 2 additions & 4 deletions example/src/components/bitcoin/SendBtc/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useCallback, useState } from 'react';
import Wallet, { BitcoinNetworkType } from 'sats-connect';
import { Button, Card, Input, Success } from '../../../App.styles';
import { getMempoolEndpoint } from '../../../util';

interface Props {
network: BitcoinNetworkType;
Expand Down Expand Up @@ -52,10 +53,7 @@ export const SendBtc = ({ network }: Props) => {
})().catch(console.error);
}, [recipients]);

const explorerUrl =
network === BitcoinNetworkType.Mainnet
? `https://mempool.space/tx/${txnId}`
: `https://mempool.space/testnet/tx/${txnId}`;
const explorerUrl = `${getMempoolEndpoint(network)}tx/${txnId}`;

return (
<Card>
Expand Down
52 changes: 52 additions & 0 deletions example/src/components/createInscription/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { useCallback, useState } from 'react';
import { BitcoinNetworkType, createInscription } from 'sats-connect';
import { Button, Card, Input } from '../../App.styles';

interface Props {
network: BitcoinNetworkType;
}

export const CreateInscription = ({ network }: Props) => {
const [content, setContent] = useState<string>('');

const onClick = useCallback(() => {
(async () => {
alert(content);
await createInscription({
payload: {
network: {
type: network,
},
contentType: 'text/plain',
content: content,
payloadType: 'PLAIN_TEXT',
},
onFinish: (response) => {
alert(response.txId);
},
onCancel: () => alert('Canceled'),
});
})().catch(console.error);
}, [content]);

return (
<Card>
<h3>Create Inscription</h3>
<h4>Sample BRC20 deploy payload</h4>
<pre>{'{ "p": "brc-20","op": "deploy","tick": "rrfq","max": "21000000","lim": "1000"}'}</pre>

<h4>Sample BRC20 mint payload</h4>
<pre>{'{ "p": "brc-20","op": "mint","tick": "rrfq","amt": "1000" }'}</pre>

<h2>Inscription text/plain payload</h2>
<Input
type="text"
placeholder="Payload"
value={content}
onChange={(e) => setContent(e.target.value)}
/>

<Button onClick={onClick}>Create inscription</Button>
</Card>
);
};
9 changes: 2 additions & 7 deletions example/src/components/transferRunes/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useCallback, useMemo, useState } from 'react';
import Wallet, { BitcoinNetworkType } from 'sats-connect';
import { Button, Card, Input, Success } from '../../App.styles';
import { getMempoolEndpoint } from '../../util';

interface Props {
network: BitcoinNetworkType;
Expand Down Expand Up @@ -52,13 +53,7 @@ const TransferRunes = ({ network }: Props) => {
})().catch(console.error);
}, [recipients]);

const explorerUrl = useMemo(
() =>
network === BitcoinNetworkType.Mainnet
? `https://mempool.space/tx/${txnId}`
: `https://mempool.space/testnet/tx/${txnId}`,
[network, txnId]
);
const explorerUrl = useMemo(() => `${getMempoolEndpoint(network)}tx/${txnId}`, [network, txnId]);

return (
<Card>
Expand Down
17 changes: 17 additions & 0 deletions example/src/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { BitcoinNetworkType } from '@sats-connect/core';

export function getMempoolEndpoint(network: BitcoinNetworkType): string {
let url = 'https://mempool.space/';
switch (network) {
case BitcoinNetworkType.Testnet:
url += 'testnet/';
break;
case BitcoinNetworkType.Signet:
url += 'signet/';
break;
case BitcoinNetworkType.Testnet4:
url += 'testnet4/';
break;
}
return url;
}
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sats-connect",
"version": "3.0.1",
"version": "3.0.2",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plz run npm i after changing this so the lock file is also updated 🙏

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

"main": "dist/index.mjs",
"files": [
"dist"
Expand All @@ -24,7 +24,7 @@
]
},
"dependencies": {
"@sats-connect/core": "0.4.1",
"@sats-connect/core": "0.5.2",
"@sats-connect/make-default-provider-config": "0.0.10",
"@sats-connect/ui": "0.0.7"
},
Expand Down
Loading