From a5fb08bcdefb3588aff22b0364fa63bbcf7779fc Mon Sep 17 00:00:00 2001 From: Mahmoud Aboelenein Date: Mon, 15 Apr 2024 13:37:02 +0200 Subject: [PATCH 1/5] added etching example --- example/src/App.tsx | 10 +- example/src/components/EtchRunes/index.tsx | 147 +++++++++++++++++++++ example/src/components/index.ts | 1 + 3 files changed, 157 insertions(+), 1 deletion(-) create mode 100644 example/src/components/EtchRunes/index.tsx diff --git a/example/src/App.tsx b/example/src/App.tsx index 2a9807c..0daa8b5 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -1,6 +1,13 @@ import Wallet, { Address, BitcoinNetworkType, AddressPurpose } from 'sats-connect'; import './App.css'; -import { AddressDisplay, NetworkSelector, SendBtc, SendStx, MintRunes } from './components'; +import { + AddressDisplay, + NetworkSelector, + SendBtc, + SendStx, + MintRunes, + EtchRunes, +} from './components'; import { useLocalStorage } from './hooks'; function App() { @@ -51,6 +58,7 @@ function App() { + ); diff --git a/example/src/components/EtchRunes/index.tsx b/example/src/components/EtchRunes/index.tsx new file mode 100644 index 0000000..e9a01bd --- /dev/null +++ b/example/src/components/EtchRunes/index.tsx @@ -0,0 +1,147 @@ +import { useMemo, useState } from 'react'; +import Wallet, { Address, AddressPurpose, BitcoinNetworkType } from 'sats-connect'; + +type Props = { + network: BitcoinNetworkType; + addresses: Address[]; +}; + +const EtchRunes = ({ addresses, network }: Props) => { + const [totalCost, setTotalCost] = useState(); + const [totalSize, setTotalSize] = useState(); + const [fundTxId, setFundTxId] = useState(''); + const [runeName, setRuneName] = useState(''); + const [feeRate, setFeeRate] = useState(''); + const [symbol, setSymbol] = useState(''); + const [preMine, setPreMine] = useState(''); + const [divisibility, setDivisibility] = useState(''); + + const ordinalsAddress = useMemo( + () => addresses.find((a) => a.purpose === AddressPurpose.Ordinals)?.address || '', + [addresses] + ); + + const paymentAddress = useMemo( + () => addresses.find((a) => a.purpose === AddressPurpose.Payment)?.address || '', + [addresses] + ); + + const onClickEstimate = async () => { + const response = await Wallet.request('runes_estimateEtch', { + destinationAddress: ordinalsAddress, + feeRate: +feeRate, + symbol: symbol || undefined, + premine: preMine || undefined, + divisibility: +divisibility || undefined, + isMintable: true, + runeName: runeName, + network: network, + }); + + if (response.status === 'success') { + setTotalCost(response.result.totalCost); + setTotalSize(response.result.totalSize); + } else { + console.error(response.error); + alert('Error Fetching Estimate. See console for details.'); + } + }; + + const onClickExecute = async () => { + const response = await Wallet.request('runes_etch', { + destinationAddress: ordinalsAddress, + symbol: symbol || undefined, + premine: preMine || undefined, + feeRate: +feeRate, + isMintable: true, + runeName, + refundAddress: paymentAddress, + network, + }); + + if (response.status === 'success') { + setFundTxId(response.result.fundTransactionId); + } else { + console.error(response.error); + alert('Error sending BTC. See console for details.'); + } + }; + + const fundTxLink = + network === BitcoinNetworkType.Mainnet + ? `https://mempool.space/tx/${fundTxId}` + : `https://mempool.space/testnet/tx/${fundTxId}`; + + return ( + <> +
+

Etch Runes

+
+
+

Rune Name

+ setRuneName(e.target.value)} /> +
+
+

Symbol

+ setSymbol(e.target.value)} /> +
+
+

Divisibility

+ setDivisibility(e.target.value)} + /> +
+
+

Premine

+ setPreMine(e.target.value)} /> +
+
+

feeRate (sats/vb)

+ setFeeRate(e.target.value)} /> +
+
+ + +
+ + {totalCost && ( +
+
+

Rune Name

+

{runeName}

+
+
+

Total Cost (sats) - Total Size

+

+ {totalCost} - {totalSize} +

+
+ + {fundTxId && ( +
+ Success! Click{' '} + + here + {' '} + to see your transaction +
+ )} +
+ )} + + ); +}; + +export default EtchRunes; diff --git a/example/src/components/index.ts b/example/src/components/index.ts index f6ea304..1debe0a 100644 --- a/example/src/components/index.ts +++ b/example/src/components/index.ts @@ -3,3 +3,4 @@ export { default as NetworkSelector } from './NetworkSelector'; export { default as SendBtc } from './SendBtc'; export { default as SendStx } from './SendStx'; export { default as MintRunes } from './MintRunes'; +export { default as EtchRunes } from './EtchRunes'; From f9d624a31178860fce0e7042cb87285281d82103 Mon Sep 17 00:00:00 2001 From: Mahmoud Aboelenein Date: Mon, 15 Apr 2024 16:31:09 +0200 Subject: [PATCH 2/5] added an amount and cap fields to etch --- example/src/components/EtchRunes/index.tsx | 24 ++++++++++++++++++++++ package.json | 1 + 2 files changed, 25 insertions(+) diff --git a/example/src/components/EtchRunes/index.tsx b/example/src/components/EtchRunes/index.tsx index e9a01bd..cd25d18 100644 --- a/example/src/components/EtchRunes/index.tsx +++ b/example/src/components/EtchRunes/index.tsx @@ -15,6 +15,8 @@ const EtchRunes = ({ addresses, network }: Props) => { const [symbol, setSymbol] = useState(''); const [preMine, setPreMine] = useState(''); const [divisibility, setDivisibility] = useState(''); + const [amount, setAmount] = useState(''); + const [mintCap, setMintCap] = useState(''); const ordinalsAddress = useMemo( () => addresses.find((a) => a.purpose === AddressPurpose.Ordinals)?.address || '', @@ -33,6 +35,13 @@ const EtchRunes = ({ addresses, network }: Props) => { symbol: symbol || undefined, premine: preMine || undefined, divisibility: +divisibility || undefined, + terms: + amount || mintCap + ? { + amount: amount || undefined, + cap: mintCap || undefined, + } + : undefined, isMintable: true, runeName: runeName, network: network, @@ -52,6 +61,13 @@ const EtchRunes = ({ addresses, network }: Props) => { destinationAddress: ordinalsAddress, symbol: symbol || undefined, premine: preMine || undefined, + terms: + amount || mintCap + ? { + amount: amount || undefined, + cap: mintCap || undefined, + } + : undefined, feeRate: +feeRate, isMintable: true, runeName, @@ -105,6 +121,14 @@ const EtchRunes = ({ addresses, network }: Props) => {

Premine

setPreMine(e.target.value)} /> +
+

Amount

+ setAmount(e.target.value)} /> +
+
+

Mint Cap

+ setMintCap(e.target.value)} /> +

feeRate (sats/vb)

setFeeRate(e.target.value)} /> diff --git a/package.json b/package.json index d1ce671..97251f8 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "scripts": { "test": "jest", "build": "npm run clean && tsup src/index.ts --format esm --dts", + "dev:build": "tsup src/index.ts --format esm --dts --watch", "dev:example": "cd example && npm start", "clean": "rimraf dist", "lint": "prettier --write .", From f8f4e84ae0a5a23e5a589f5539301b1f42720fb0 Mon Sep 17 00:00:00 2001 From: Mahmoud Aboelenein Date: Mon, 15 Apr 2024 16:37:45 +0200 Subject: [PATCH 3/5] update core version --- example/package-lock.json | 2 +- package-lock.json | 14 +++++++------- package.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/example/package-lock.json b/example/package-lock.json index 99673d6..23965b3 100644 --- a/example/package-lock.json +++ b/example/package-lock.json @@ -23,7 +23,7 @@ "version": "2.2.0", "license": "ISC", "dependencies": { - "@sats-connect/core": "0.0.5", + "@sats-connect/core": "0.0.6-47b5ced", "@sats-connect/make-default-provider-config": "0.0.1", "@sats-connect/ui": "0.0.4" }, diff --git a/package-lock.json b/package-lock.json index 6410633..1dc57ea 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "2.2.0", "license": "ISC", "dependencies": { - "@sats-connect/core": "0.0.5", + "@sats-connect/core": "0.0.6-47b5ced", "@sats-connect/make-default-provider-config": "0.0.1", "@sats-connect/ui": "0.0.4" }, @@ -1748,9 +1748,9 @@ ] }, "node_modules/@sats-connect/core": { - "version": "0.0.5", - "resolved": "https://registry.npmjs.org/@sats-connect/core/-/core-0.0.5.tgz", - "integrity": "sha512-eyAoxjs3vuJP037/XKuhjIDUrOlCHIdcvw2D1DFpzhTRzyiXptiE2A0n46loDIBCUhOuXl4vsn8cc+yC2jzGCg==", + "version": "0.0.6-47b5ced", + "resolved": "https://registry.npmjs.org/@sats-connect/core/-/core-0.0.6-47b5ced.tgz", + "integrity": "sha512-JpZBJsRDmBzJgQZ4AwSgcgcaXm35LTNdnjdLUo5mag62M2UCx9NsRbViaVXOvrRp+vV7xKINtRm4RrFXnOaq6w==", "dependencies": { "axios": "1.6.8", "bitcoin-address-validation": "2.2.3", @@ -7337,9 +7337,9 @@ "optional": true }, "@sats-connect/core": { - "version": "0.0.5", - "resolved": "https://registry.npmjs.org/@sats-connect/core/-/core-0.0.5.tgz", - "integrity": "sha512-eyAoxjs3vuJP037/XKuhjIDUrOlCHIdcvw2D1DFpzhTRzyiXptiE2A0n46loDIBCUhOuXl4vsn8cc+yC2jzGCg==", + "version": "0.0.6-47b5ced", + "resolved": "https://registry.npmjs.org/@sats-connect/core/-/core-0.0.6-47b5ced.tgz", + "integrity": "sha512-JpZBJsRDmBzJgQZ4AwSgcgcaXm35LTNdnjdLUo5mag62M2UCx9NsRbViaVXOvrRp+vV7xKINtRm4RrFXnOaq6w==", "requires": { "axios": "1.6.8", "bitcoin-address-validation": "2.2.3", diff --git a/package.json b/package.json index 97251f8..ff06f6f 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ ] }, "dependencies": { - "@sats-connect/core": "0.0.5", + "@sats-connect/core": "0.0.6-47b5ced", "@sats-connect/ui": "0.0.4", "@sats-connect/make-default-provider-config": "0.0.1" }, From 095b303d5d2a80b8a5655481363bd0433c61d909 Mon Sep 17 00:00:00 2001 From: Mahmoud Aboelenein Date: Tue, 16 Apr 2024 08:11:42 +0200 Subject: [PATCH 4/5] update core + export wallet instance --- example/package-lock.json | 2 +- package-lock.json | 14 +++++++------- package.json | 2 +- src/index.ts | 20 +++++++++----------- 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/example/package-lock.json b/example/package-lock.json index 23965b3..a6954a9 100644 --- a/example/package-lock.json +++ b/example/package-lock.json @@ -23,7 +23,7 @@ "version": "2.2.0", "license": "ISC", "dependencies": { - "@sats-connect/core": "0.0.6-47b5ced", + "@sats-connect/core": "0.0.6-92acf81", "@sats-connect/make-default-provider-config": "0.0.1", "@sats-connect/ui": "0.0.4" }, diff --git a/package-lock.json b/package-lock.json index 1dc57ea..c70d130 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "2.2.0", "license": "ISC", "dependencies": { - "@sats-connect/core": "0.0.6-47b5ced", + "@sats-connect/core": "0.0.6-92acf81", "@sats-connect/make-default-provider-config": "0.0.1", "@sats-connect/ui": "0.0.4" }, @@ -1748,9 +1748,9 @@ ] }, "node_modules/@sats-connect/core": { - "version": "0.0.6-47b5ced", - "resolved": "https://registry.npmjs.org/@sats-connect/core/-/core-0.0.6-47b5ced.tgz", - "integrity": "sha512-JpZBJsRDmBzJgQZ4AwSgcgcaXm35LTNdnjdLUo5mag62M2UCx9NsRbViaVXOvrRp+vV7xKINtRm4RrFXnOaq6w==", + "version": "0.0.6-92acf81", + "resolved": "https://registry.npmjs.org/@sats-connect/core/-/core-0.0.6-92acf81.tgz", + "integrity": "sha512-GeM5MLM1RaeisNfNyUHdJipjzKLTYQ1PMicPwhKAzpHEswX+j+RaDVhFhGgpvi9RNYnbjRzShrsMb/1GCcTr0Q==", "dependencies": { "axios": "1.6.8", "bitcoin-address-validation": "2.2.3", @@ -7337,9 +7337,9 @@ "optional": true }, "@sats-connect/core": { - "version": "0.0.6-47b5ced", - "resolved": "https://registry.npmjs.org/@sats-connect/core/-/core-0.0.6-47b5ced.tgz", - "integrity": "sha512-JpZBJsRDmBzJgQZ4AwSgcgcaXm35LTNdnjdLUo5mag62M2UCx9NsRbViaVXOvrRp+vV7xKINtRm4RrFXnOaq6w==", + "version": "0.0.6-92acf81", + "resolved": "https://registry.npmjs.org/@sats-connect/core/-/core-0.0.6-92acf81.tgz", + "integrity": "sha512-GeM5MLM1RaeisNfNyUHdJipjzKLTYQ1PMicPwhKAzpHEswX+j+RaDVhFhGgpvi9RNYnbjRzShrsMb/1GCcTr0Q==", "requires": { "axios": "1.6.8", "bitcoin-address-validation": "2.2.3", diff --git a/package.json b/package.json index ff06f6f..ddc11f9 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ ] }, "dependencies": { - "@sats-connect/core": "0.0.6-47b5ced", + "@sats-connect/core": "0.0.6-92acf81", "@sats-connect/ui": "0.0.4", "@sats-connect/make-default-provider-config": "0.0.1" }, diff --git a/src/index.ts b/src/index.ts index c959cb3..565ee25 100644 --- a/src/index.ts +++ b/src/index.ts @@ -25,23 +25,21 @@ import { makeDefaultConfig } from '@sats-connect/make-default-provider-config'; loadSelector(); class Wallet { - private static providerId: string | undefined; + private providerId: string | undefined; - private static defaultAdapters: Record SatsConnectAdapter> = defaultAdapters; + private defaultAdapters: Record SatsConnectAdapter> = defaultAdapters; - private static createCustomConfig?: (providers: SupportedWallet[]) => Config; + private createCustomConfig?: (providers: SupportedWallet[]) => Config; - private static isProviderSet(): boolean { + private isProviderSet(): boolean { return !!this.providerId; } - public static setCreateCustomConfig( - createCustomConfig: (providers: SupportedWallet[]) => Config - ) { + public setCreateCustomConfig(createCustomConfig: (providers: SupportedWallet[]) => Config) { this.createCustomConfig = createCustomConfig; } - public static async selectProvider() { + public async selectProvider() { const providers = getSupportedWallets(); if (providers.length === 0) { @@ -57,12 +55,12 @@ class Wallet { this.providerId = nextProviderId; } - public static async disconnect() { + public async disconnect() { this.providerId = undefined; removeDefaultProvider(); } - public static async request( + public async request( method: Method, params: Params ): Promise> { @@ -114,4 +112,4 @@ class Wallet { export * from '@sats-connect/core'; -export default Wallet; +export default new Wallet(); From 1a0c8379cd5ae3b07a7625f4b294faf09fad875c Mon Sep 17 00:00:00 2001 From: Mahmoud Aboelenein Date: Tue, 16 Apr 2024 16:40:24 +0200 Subject: [PATCH 5/5] update core version --- example/package-lock.json | 2 +- package-lock.json | 14 +++++++------- package.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/example/package-lock.json b/example/package-lock.json index a6954a9..f644a6e 100644 --- a/example/package-lock.json +++ b/example/package-lock.json @@ -23,7 +23,7 @@ "version": "2.2.0", "license": "ISC", "dependencies": { - "@sats-connect/core": "0.0.6-92acf81", + "@sats-connect/core": "0.0.6", "@sats-connect/make-default-provider-config": "0.0.1", "@sats-connect/ui": "0.0.4" }, diff --git a/package-lock.json b/package-lock.json index c70d130..c405288 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "2.2.0", "license": "ISC", "dependencies": { - "@sats-connect/core": "0.0.6-92acf81", + "@sats-connect/core": "0.0.6", "@sats-connect/make-default-provider-config": "0.0.1", "@sats-connect/ui": "0.0.4" }, @@ -1748,9 +1748,9 @@ ] }, "node_modules/@sats-connect/core": { - "version": "0.0.6-92acf81", - "resolved": "https://registry.npmjs.org/@sats-connect/core/-/core-0.0.6-92acf81.tgz", - "integrity": "sha512-GeM5MLM1RaeisNfNyUHdJipjzKLTYQ1PMicPwhKAzpHEswX+j+RaDVhFhGgpvi9RNYnbjRzShrsMb/1GCcTr0Q==", + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/@sats-connect/core/-/core-0.0.6.tgz", + "integrity": "sha512-ShKqJamN1DQkeLAuzA2Clpu9R5jN6hhrm2UHoxnuNWWhkLK4koRbyOnJzxjkOpImtSd7MDEMibqt9NiKR/r8ow==", "dependencies": { "axios": "1.6.8", "bitcoin-address-validation": "2.2.3", @@ -7337,9 +7337,9 @@ "optional": true }, "@sats-connect/core": { - "version": "0.0.6-92acf81", - "resolved": "https://registry.npmjs.org/@sats-connect/core/-/core-0.0.6-92acf81.tgz", - "integrity": "sha512-GeM5MLM1RaeisNfNyUHdJipjzKLTYQ1PMicPwhKAzpHEswX+j+RaDVhFhGgpvi9RNYnbjRzShrsMb/1GCcTr0Q==", + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/@sats-connect/core/-/core-0.0.6.tgz", + "integrity": "sha512-ShKqJamN1DQkeLAuzA2Clpu9R5jN6hhrm2UHoxnuNWWhkLK4koRbyOnJzxjkOpImtSd7MDEMibqt9NiKR/r8ow==", "requires": { "axios": "1.6.8", "bitcoin-address-validation": "2.2.3", diff --git a/package.json b/package.json index ddc11f9..87c3595 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ ] }, "dependencies": { - "@sats-connect/core": "0.0.6-92acf81", + "@sats-connect/core": "0.0.6", "@sats-connect/ui": "0.0.4", "@sats-connect/make-default-provider-config": "0.0.1" },