@abstraxn/signer-react 1.0.16 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +101 -5
- package/dist/src/components/AbstraxnProvider/AbstraxnProviderInner.js +23 -0
- package/dist/src/components/AbstraxnProvider/AbstraxnProviderInner.js.map +1 -1
- package/dist/src/components/WalletModal/hooks/useSendTransaction.js +36 -7
- package/dist/src/components/WalletModal/hooks/useSendTransaction.js.map +1 -1
- package/dist/src/hooks.d.ts +131 -0
- package/dist/src/hooks.js +275 -0
- package/dist/src/hooks.js.map +1 -1
- package/dist/src/index.d.ts +2 -2
- package/dist/src/index.js +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/types.d.ts +3 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -98,11 +98,107 @@ function HookConnectButton() {
|
|
|
98
98
|
|
|
99
99
|
- `useAbstraxnWallet()` - Main wallet hook
|
|
100
100
|
- `useIsConnected()` - Check connection status
|
|
101
|
-
- `useAddress()` - Get wallet address
|
|
102
|
-
- `useWhoami()` - Get user information
|
|
103
|
-
- `useExternalWalletInfo()` - External wallet information
|
|
104
|
-
- `
|
|
105
|
-
- `
|
|
101
|
+
- `useAddress()` - Get wallet address (EVM)
|
|
102
|
+
- `useWhoami()` - Get user information (includes `solanaAddress` when available)
|
|
103
|
+
- `useExternalWalletInfo()` - External wallet information (EVM)
|
|
104
|
+
- `useExportWallet()` - Export wallet (EVM or Solana, based on current chain)
|
|
105
|
+
- `usePublicClient()` / `usePrepareRawTxn()` / `useSignTxn()` / `useSignAndSendTxn()` / `useWaitForTxnReceipt()` - EVM transaction flow (prepare → sign → send → confirm)
|
|
106
|
+
- `useSolanaConnection()` / `useSolanaPublicKey()` / `usePrepareSolanaTxn()` / `useSignSolanaTxn()` / `useSignAndSendSolanaTxn()` / `useWaitForSolanaConfirmation()` - Solana transaction flow (prepare → sign → send → confirm)
|
|
107
|
+
|
|
108
|
+
### Example: EVM → Solana flow after social/email login
|
|
109
|
+
|
|
110
|
+
```tsx
|
|
111
|
+
import {
|
|
112
|
+
useAbstraxnWallet,
|
|
113
|
+
usePublicClient,
|
|
114
|
+
usePrepareRawTxn,
|
|
115
|
+
useEstimateGas,
|
|
116
|
+
useGetGasPrice,
|
|
117
|
+
useSignAndSendTxn,
|
|
118
|
+
useWaitForTxnReceipt,
|
|
119
|
+
useSolanaConnection,
|
|
120
|
+
useSolanaPublicKey,
|
|
121
|
+
usePrepareSolanaTxn,
|
|
122
|
+
useSignAndSendSolanaTxn,
|
|
123
|
+
useWaitForSolanaConfirmation,
|
|
124
|
+
} from '@abstraxn/signer-react';
|
|
125
|
+
import { polygonAmoy } from 'viem/chains';
|
|
126
|
+
|
|
127
|
+
function CrossChainExample() {
|
|
128
|
+
const { isConnected } = useAbstraxnWallet();
|
|
129
|
+
|
|
130
|
+
// EVM clients & hooks
|
|
131
|
+
const { publicClient } = usePublicClient(
|
|
132
|
+
polygonAmoy,
|
|
133
|
+
'https://rpc-amoy.polygon.technology'
|
|
134
|
+
);
|
|
135
|
+
const { prepareRawTxn } = usePrepareRawTxn(publicClient);
|
|
136
|
+
const { estimateGas } = useEstimateGas(publicClient);
|
|
137
|
+
const { getGasPrice } = useGetGasPrice(publicClient);
|
|
138
|
+
const { signAndSendTxn } = useSignAndSendTxn(publicClient);
|
|
139
|
+
const { waitForTxnReceipt } = useWaitForTxnReceipt(publicClient);
|
|
140
|
+
|
|
141
|
+
// Solana clients & hooks
|
|
142
|
+
const { connection } = useSolanaConnection('https://api.devnet.solana.com');
|
|
143
|
+
const { solanaAddress } = useSolanaPublicKey();
|
|
144
|
+
const { prepareSolanaTransfer } = usePrepareSolanaTxn(connection);
|
|
145
|
+
const { signAndSendSolanaTxn } = useSignAndSendSolanaTxn(connection);
|
|
146
|
+
const { waitForSolanaConfirmation } = useWaitForSolanaConfirmation(connection);
|
|
147
|
+
|
|
148
|
+
const handleCrossChain = async () => {
|
|
149
|
+
if (!isConnected) throw new Error('Please login first');
|
|
150
|
+
|
|
151
|
+
// 1) EVM tx (e.g. on Polygon Amoy)
|
|
152
|
+
const from = '0x...'; // current EVM address
|
|
153
|
+
const rawTx = await prepareRawTxn({
|
|
154
|
+
from,
|
|
155
|
+
to: '0x...',
|
|
156
|
+
value: '0.001',
|
|
157
|
+
});
|
|
158
|
+
const { gasLimit } = await estimateGas({
|
|
159
|
+
account: from,
|
|
160
|
+
to: rawTx.to,
|
|
161
|
+
data: rawTx.data,
|
|
162
|
+
value: rawTx.value,
|
|
163
|
+
});
|
|
164
|
+
const fees = await getGasPrice();
|
|
165
|
+
|
|
166
|
+
const evmResult = await signAndSendTxn({
|
|
167
|
+
from,
|
|
168
|
+
...rawTx,
|
|
169
|
+
gas: {
|
|
170
|
+
gasLimit,
|
|
171
|
+
maxFeePerGas: fees.maxFeePerGas!,
|
|
172
|
+
maxPriorityFeePerGas: fees.maxPriorityFeePerGas!,
|
|
173
|
+
},
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
await waitForTxnReceipt({ hash: evmResult.hash, confirmations: 1 });
|
|
177
|
+
|
|
178
|
+
// 2) After EVM confirmation, send SOL
|
|
179
|
+
if (!solanaAddress) throw new Error('Solana wallet not provisioned');
|
|
180
|
+
|
|
181
|
+
const { transaction } = await prepareSolanaTransfer({
|
|
182
|
+
fromPubkey: solanaAddress,
|
|
183
|
+
toPubkey: 'TargetSolanaAddressHere',
|
|
184
|
+
amountInSol: 0.01,
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
const solanaResult = await signAndSendSolanaTxn({
|
|
188
|
+
transaction,
|
|
189
|
+
fromPubkey: solanaAddress,
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
await waitForSolanaConfirmation({ signature: solanaResult.signature });
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
return (
|
|
196
|
+
<button onClick={handleCrossChain}>
|
|
197
|
+
Run EVM → Solana Flow
|
|
198
|
+
</button>
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
```
|
|
106
202
|
|
|
107
203
|
## 🔗 Related Packages
|
|
108
204
|
|
|
@@ -1725,6 +1725,28 @@ export function AbstraxnProviderInner({ config, children, base, wagmi, }) {
|
|
|
1725
1725
|
setLoading(false);
|
|
1726
1726
|
}
|
|
1727
1727
|
}, []);
|
|
1728
|
+
// Sign Solana transaction via API (returns signed transaction)
|
|
1729
|
+
const signSolanaTransactionViaAPI = useCallback(async (unsignedTransaction, fromAddress) => {
|
|
1730
|
+
if (!walletRef.current)
|
|
1731
|
+
throw new Error("Wallet not initialized");
|
|
1732
|
+
setLoading(true);
|
|
1733
|
+
setError(null);
|
|
1734
|
+
try {
|
|
1735
|
+
const walletAny = walletRef.current;
|
|
1736
|
+
if (typeof walletAny.signSolanaTransactionViaAPI !== "function") {
|
|
1737
|
+
throw new Error("Solana transaction signing is not supported by this wallet");
|
|
1738
|
+
}
|
|
1739
|
+
return await walletAny.signSolanaTransactionViaAPI(unsignedTransaction, fromAddress);
|
|
1740
|
+
}
|
|
1741
|
+
catch (err) {
|
|
1742
|
+
const error = err instanceof Error ? err : new Error("Failed to sign Solana transaction");
|
|
1743
|
+
setError(error);
|
|
1744
|
+
throw error;
|
|
1745
|
+
}
|
|
1746
|
+
finally {
|
|
1747
|
+
setLoading(false);
|
|
1748
|
+
}
|
|
1749
|
+
}, []);
|
|
1728
1750
|
// Sign typed data / raw payload via API (same flow as signTransactionViaAPI, payload: from, unsignedTransaction, encoding, hashFunction)
|
|
1729
1751
|
const signTypedTxViaAPI = useCallback(async (fromAddress, unsignedTransaction, encoding, hashFunction) => {
|
|
1730
1752
|
if (!walletRef.current)
|
|
@@ -2855,6 +2877,7 @@ export function AbstraxnProviderInner({ config, children, base, wagmi, }) {
|
|
|
2855
2877
|
signTransaction,
|
|
2856
2878
|
sendTransaction,
|
|
2857
2879
|
signTransactionViaAPI,
|
|
2880
|
+
signSolanaTransactionViaAPI,
|
|
2858
2881
|
signTypedTxViaAPI,
|
|
2859
2882
|
signAndSendTransaction,
|
|
2860
2883
|
loginWithOTP,
|