@volr/react 0.1.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 +124 -0
- package/dist/index.cjs +2611 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +640 -0
- package/dist/index.d.ts +640 -0
- package/dist/index.js +2559 -0
- package/dist/index.js.map +1 -0
- package/package.json +79 -0
package/README.md
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# @volr/react
|
|
2
|
+
|
|
3
|
+
Volr React SDK - React hooks and UI components for Volr Web3 Payment Builder.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
yarn add @volr/react
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
### Basic Setup
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { VolrProvider, useVolrWallet } from '@volr/react';
|
|
17
|
+
|
|
18
|
+
function App() {
|
|
19
|
+
return (
|
|
20
|
+
<VolrProvider
|
|
21
|
+
config={{
|
|
22
|
+
apiBaseUrl: 'https://api.volr.io',
|
|
23
|
+
defaultChainId: 8453,
|
|
24
|
+
invokerAddressMap: {
|
|
25
|
+
8453: '0x...',
|
|
26
|
+
},
|
|
27
|
+
}}
|
|
28
|
+
>
|
|
29
|
+
<YourApp />
|
|
30
|
+
</VolrProvider>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function YourApp() {
|
|
35
|
+
const { evm } = useVolrWallet();
|
|
36
|
+
|
|
37
|
+
// Read contract
|
|
38
|
+
const balance = await evm(8453).readContract({
|
|
39
|
+
address: '0x...',
|
|
40
|
+
abi: erc20Abi,
|
|
41
|
+
functionName: 'balanceOf',
|
|
42
|
+
args: ['0x...'],
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// Send transaction
|
|
46
|
+
const result = await evm(8453).sendTransaction(
|
|
47
|
+
{
|
|
48
|
+
to: '0x...',
|
|
49
|
+
data: '0x...',
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
policyId: '0x' + '0'.repeat(64),
|
|
53
|
+
signer: mySigner,
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Advanced Usage
|
|
60
|
+
|
|
61
|
+
For advanced users who need more control, you can use the low-level hooks:
|
|
62
|
+
|
|
63
|
+
```tsx
|
|
64
|
+
import { usePrecheck, useRelay, buildCall } from '@volr/react';
|
|
65
|
+
|
|
66
|
+
function AdvancedComponent() {
|
|
67
|
+
const { precheck } = usePrecheck();
|
|
68
|
+
const { relay } = useRelay();
|
|
69
|
+
|
|
70
|
+
// Build call manually
|
|
71
|
+
const call = buildCall({
|
|
72
|
+
target: '0x...',
|
|
73
|
+
abi: erc20Abi,
|
|
74
|
+
functionName: 'transfer',
|
|
75
|
+
args: ['0x...', BigInt(1000000)],
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// Use precheck and relay directly
|
|
79
|
+
const quote = await precheck({ auth, calls: [call] });
|
|
80
|
+
const result = await relay(input, { signer, rpcClient });
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Features
|
|
85
|
+
|
|
86
|
+
- **Developer-Friendly API**: `useVolrWallet()` provides a simple, intuitive interface
|
|
87
|
+
- **Session Management**: Automatic token refresh and tab synchronization
|
|
88
|
+
- **EIP-7702 Support**: Gasless transactions with session keys
|
|
89
|
+
- **Passkey Integration**: Secure signing with device passkeys
|
|
90
|
+
- **Type-Safe**: Full TypeScript support
|
|
91
|
+
- **SSR Safe**: Works with Next.js and other SSR frameworks
|
|
92
|
+
- **Call Builders**: `buildCall()` and `buildCalls()` utilities for easy transaction building
|
|
93
|
+
|
|
94
|
+
## Failure Semantics
|
|
95
|
+
|
|
96
|
+
- Relay enforces strict failure-by-default:
|
|
97
|
+
- `revertOnFail` defaults to `true` and any failed call reverts the entire batch.
|
|
98
|
+
- Calls to non-contract addresses are rejected.
|
|
99
|
+
- For ERC20 methods (`transfer`, `transferFrom`, `approve`, `increaseAllowance`, `decreaseAllowance`), if a token returns `false`, the batch is treated as failed (even if it doesn't revert).
|
|
100
|
+
- Backend precheck rejects obvious failures (non-contract targets; ERC20 `false` on simulation) before submitting.
|
|
101
|
+
|
|
102
|
+
## Diagnostics
|
|
103
|
+
|
|
104
|
+
When gas estimation or simulation fails, the backend includes a `developerDiagnostics` object in the error response (and FAILED transaction meta). This contains:
|
|
105
|
+
|
|
106
|
+
- `topLevel.reason`: Decoded revert reason for the overall execution attempt
|
|
107
|
+
- `calls[]`: Per-call diagnostics with:
|
|
108
|
+
- `index`, `target`, `selector`
|
|
109
|
+
- `isContract` (EOA detection)
|
|
110
|
+
- `callResult` (raw `eth_call` return data)
|
|
111
|
+
- `decodedRevert` (human-readable when available)
|
|
112
|
+
|
|
113
|
+
The SDK surfaces these in console for convenience:
|
|
114
|
+
- Precheck errors: `[volr][precheck] developerDiagnostics: ...`
|
|
115
|
+
- Relay errors: `[volr][relay] developerDiagnostics: ...`
|
|
116
|
+
|
|
117
|
+
Use these to pinpoint which call failed and why (e.g., EOA target, ERC20 returned false, custom revert).
|
|
118
|
+
|
|
119
|
+
## Documentation
|
|
120
|
+
|
|
121
|
+
- **[React Integration Guide](./REACT_INTEGRATION.md)** - Complete guide for integrating Volr React SDK
|
|
122
|
+
- **[Contract Integration Guide](../CONTRACT_INTEGRATION.md)** - Guide for SDK engineers
|
|
123
|
+
- [Volr Documentation](https://docs.volr.io) - Detailed API reference
|
|
124
|
+
|