@vela-ventures/aosync-sdk-react 1.0.3 → 1.0.5
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 +95 -25
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/{walletProvider.d.ts → types.d.ts} +1 -7
- package/dist/types.js +1 -0
- package/dist/useWallet.d.ts +1 -0
- package/dist/useWallet.js +9 -1
- package/dist/walletContext.d.ts +10 -0
- package/dist/{walletProvider.js → walletContext.js} +21 -29
- package/package.json +26 -2
- package/dist/component.d.ts +0 -4
- package/dist/component.js +0 -5
- package/dist/component.js.map +0 -1
- package/dist/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,37 +1,107 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Wallet SDK for Arweave and AO
|
|
2
2
|
|
|
3
|
-
A
|
|
3
|
+
A lightweight React hook and context provider for integrating the Beacon Wallet into your React applications.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Easily manage wallet connections.
|
|
8
|
+
- Send AR transactions.
|
|
9
|
+
- Sign messages and transactions.
|
|
10
|
+
- Retrieve wallet addresses.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
6
13
|
|
|
7
|
-
|
|
8
|
-
import { AOSyncProvider, useWallet } from "@vela-ventures/aosync-react-sdk";
|
|
14
|
+
Install the package via npm:
|
|
9
15
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
16
|
+
```bash
|
|
17
|
+
npm install @vela-ventures/aosync-sdk-react
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
13
21
|
|
|
14
|
-
|
|
15
|
-
setAddress(wallet.getAddress())
|
|
16
|
-
}, [wallet.isConnected])
|
|
22
|
+
### 1: Wrap Your App with WalletProvider
|
|
17
23
|
|
|
18
|
-
|
|
19
|
-
return(
|
|
20
|
-
<>
|
|
21
|
-
<h1>Connected to: {address}</h1>
|
|
22
|
-
<Button onClick={wallet.disconnect}>Disconnect Wallet</Button>
|
|
23
|
-
</>
|
|
24
|
-
)
|
|
25
|
-
}
|
|
24
|
+
To enable wallet functionality across your app, wrap your application with the AOSyncProvider:
|
|
26
25
|
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
```javascript
|
|
27
|
+
import React from "react";
|
|
28
|
+
import { AOSyncProvider } from "@vela-ventures/aosync-sdk-react";
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
const App = () => {
|
|
31
31
|
return (
|
|
32
|
-
<AOSyncProvider
|
|
33
|
-
|
|
32
|
+
<AOSyncProvider
|
|
33
|
+
gatewayConfig={{
|
|
34
|
+
host: "arweave.net",
|
|
35
|
+
port: 443,
|
|
36
|
+
protocol: "https",
|
|
37
|
+
}}
|
|
38
|
+
muUrl="https://mu.ao-testnet.xyz"
|
|
39
|
+
>
|
|
40
|
+
<YourApp />
|
|
34
41
|
</AOSyncProvider>
|
|
35
42
|
);
|
|
36
|
-
}
|
|
43
|
+
};
|
|
37
44
|
```
|
|
45
|
+
|
|
46
|
+
### 2. Use the useWallet Hook
|
|
47
|
+
|
|
48
|
+
Access wallet functionality in any component with the useWallet hook:
|
|
49
|
+
|
|
50
|
+
```javascript
|
|
51
|
+
import React from "react";
|
|
52
|
+
import { useWallet } from "@vela-ventures/aosync-sdk-react";
|
|
53
|
+
|
|
54
|
+
const WalletComponent = () => {
|
|
55
|
+
const { isConnected, connect, disconnect, getAddress, sendAR } = useWallet();
|
|
56
|
+
|
|
57
|
+
const handleConnect = async () => {
|
|
58
|
+
await connect();
|
|
59
|
+
const address = await getAddress();
|
|
60
|
+
console.log("Connected wallet address:", address);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const handleSendAR = async () => {
|
|
64
|
+
try {
|
|
65
|
+
await sendAR("recipient-address", "1000000"); // 1 AR (in winstons)
|
|
66
|
+
console.log("AR sent successfully!");
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.error("Error sending AR:", error);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
<div>
|
|
74
|
+
<h1>Wallet Status: {isConnected ? "Connected" : "Disconnected"}</h1>
|
|
75
|
+
{!isConnected ? (
|
|
76
|
+
<button onClick={handleConnect}>Connect Wallet</button>
|
|
77
|
+
) : (
|
|
78
|
+
<button onClick={disconnect}>Disconnect Wallet</button>
|
|
79
|
+
)}
|
|
80
|
+
{isConnected && <button onClick={handleSendAR}>Send AR</button>}
|
|
81
|
+
</div>
|
|
82
|
+
);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export default WalletComponent;
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## API
|
|
89
|
+
|
|
90
|
+
### `useWallet`
|
|
91
|
+
|
|
92
|
+
The `useWallet` hook provides the following methods and properties:
|
|
93
|
+
|
|
94
|
+
| Method/Property | Description |
|
|
95
|
+
| -------------------------------------------- | ---------------------------------------------- |
|
|
96
|
+
| `isConnected` | Boolean indicating if the wallet is connected. |
|
|
97
|
+
| `connect()` | Connects to the wallet. |
|
|
98
|
+
| `disconnect()` | Disconnects from the wallet. |
|
|
99
|
+
| `getAddress()` | Returns the currently active wallet address. |
|
|
100
|
+
| `getAllAddresses()` | Returns all wallet addresses. |
|
|
101
|
+
| `sendAR(recipient, quantity)` | Sends AR to the specified address. |
|
|
102
|
+
| `sign(transaction)` | Signs a transaction using the wallet. |
|
|
103
|
+
| `signAOMessage(target, recipient, quantity)` | Signs a custom AO message. |
|
|
104
|
+
|
|
105
|
+
## License
|
|
106
|
+
|
|
107
|
+
MIT License © 2025 Vela Ventures
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import React from "react";
|
|
2
1
|
import Transaction from "arweave/web/lib/transaction";
|
|
3
|
-
interface
|
|
2
|
+
export interface AOSyncSDKContext {
|
|
4
3
|
isConnected: boolean;
|
|
5
4
|
connect: () => Promise<void>;
|
|
6
5
|
disconnect: () => Promise<void>;
|
|
@@ -10,8 +9,3 @@ interface WalletContextValue {
|
|
|
10
9
|
signAOMessage: (target: string, recipient: string, quantity: string) => Promise<any>;
|
|
11
10
|
sign: (transaction: Transaction) => Promise<Transaction>;
|
|
12
11
|
}
|
|
13
|
-
export declare const WalletProvider: ({ children, }: {
|
|
14
|
-
children: any;
|
|
15
|
-
}) => React.JSX.Element;
|
|
16
|
-
export declare const useWallet: () => WalletContextValue;
|
|
17
|
-
export {};
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/useWallet.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useWallet(): import("./types").AOSyncSDKContext;
|
package/dist/useWallet.js
CHANGED
|
@@ -1 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { AOSyncContext } from "./walletContext";
|
|
3
|
+
export function useWallet() {
|
|
4
|
+
const context = useContext(AOSyncContext);
|
|
5
|
+
if (!context) {
|
|
6
|
+
throw new Error("useWallet must be used within AoSyncProvider");
|
|
7
|
+
}
|
|
8
|
+
return context;
|
|
9
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { useWallet } from "./useWallet";
|
|
2
|
+
import React, { PropsWithChildren } from "react";
|
|
3
|
+
import { GatewayConfig } from "arconnect";
|
|
4
|
+
import { AOSyncSDKContext } from "./types";
|
|
5
|
+
export declare const AOSyncContext: React.Context<AOSyncSDKContext | undefined>;
|
|
6
|
+
interface Props extends PropsWithChildren {
|
|
7
|
+
gatewayConfig: GatewayConfig;
|
|
8
|
+
muUrl: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function AOSyncProvider({ gatewayConfig, muUrl, children, }: Props): React.JSX.Element;
|
|
@@ -7,11 +7,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
|
|
11
|
-
import
|
|
10
|
+
export { useWallet } from "./useWallet";
|
|
11
|
+
import React, { useEffect, useRef, useState, createContext, } from "react";
|
|
12
12
|
import Arweave from "arweave";
|
|
13
|
-
|
|
14
|
-
export const
|
|
13
|
+
import WalletClient from "@vela-ventures/ao-sync-sdk";
|
|
14
|
+
export const AOSyncContext = createContext(undefined);
|
|
15
|
+
export function AOSyncProvider({ gatewayConfig = { host: "arweave.net", port: 443, protocol: "https" }, muUrl = "https://mu.ao-testnet.xyz", children, }) {
|
|
15
16
|
const [isConnected, setIsConnected] = useState(false);
|
|
16
17
|
const walletRef = useRef(new WalletClient());
|
|
17
18
|
useEffect(() => {
|
|
@@ -26,16 +27,18 @@ export const WalletProvider = ({ children, }) => {
|
|
|
26
27
|
wallet.off("connected", handleConnect);
|
|
27
28
|
};
|
|
28
29
|
}, []);
|
|
29
|
-
const connect = () => __awaiter(
|
|
30
|
+
const connect = () => __awaiter(this, void 0, void 0, function* () {
|
|
30
31
|
try {
|
|
31
|
-
yield walletRef.current.connect({
|
|
32
|
+
yield walletRef.current.connect({
|
|
33
|
+
gateway: gatewayConfig,
|
|
34
|
+
});
|
|
32
35
|
}
|
|
33
36
|
catch (error) {
|
|
34
37
|
console.error("Error connecting wallet:", error);
|
|
35
38
|
throw error;
|
|
36
39
|
}
|
|
37
40
|
});
|
|
38
|
-
const disconnect = () => __awaiter(
|
|
41
|
+
const disconnect = () => __awaiter(this, void 0, void 0, function* () {
|
|
39
42
|
try {
|
|
40
43
|
yield walletRef.current.disconnect();
|
|
41
44
|
setIsConnected(false);
|
|
@@ -45,7 +48,7 @@ export const WalletProvider = ({ children, }) => {
|
|
|
45
48
|
throw error;
|
|
46
49
|
}
|
|
47
50
|
});
|
|
48
|
-
const getAddress = () => __awaiter(
|
|
51
|
+
const getAddress = () => __awaiter(this, void 0, void 0, function* () {
|
|
49
52
|
try {
|
|
50
53
|
return yield walletRef.current.getActiveAddress();
|
|
51
54
|
}
|
|
@@ -54,22 +57,18 @@ export const WalletProvider = ({ children, }) => {
|
|
|
54
57
|
throw error;
|
|
55
58
|
}
|
|
56
59
|
});
|
|
57
|
-
const getAllAddresses = () => __awaiter(
|
|
60
|
+
const getAllAddresses = () => __awaiter(this, void 0, void 0, function* () {
|
|
58
61
|
try {
|
|
59
62
|
return yield walletRef.current.getAllAddresses();
|
|
60
63
|
}
|
|
61
64
|
catch (error) {
|
|
62
|
-
console.error("Error getting
|
|
65
|
+
console.error("Error getting address:", error);
|
|
63
66
|
throw error;
|
|
64
67
|
}
|
|
65
68
|
});
|
|
66
|
-
const sendAR = (recipient, quantity) => __awaiter(
|
|
69
|
+
const sendAR = (recipient, quantity) => __awaiter(this, void 0, void 0, function* () {
|
|
67
70
|
try {
|
|
68
|
-
const arweave = Arweave.init(
|
|
69
|
-
host: "arweave.net",
|
|
70
|
-
port: 443,
|
|
71
|
-
protocol: "https",
|
|
72
|
-
});
|
|
71
|
+
const arweave = Arweave.init(gatewayConfig);
|
|
73
72
|
const tx = yield arweave.createTransaction({
|
|
74
73
|
target: recipient,
|
|
75
74
|
quantity: quantity,
|
|
@@ -82,7 +81,7 @@ export const WalletProvider = ({ children, }) => {
|
|
|
82
81
|
throw error;
|
|
83
82
|
}
|
|
84
83
|
});
|
|
85
|
-
const signAOMessage = (target, recipient, quantity) => __awaiter(
|
|
84
|
+
const signAOMessage = (target, recipient, quantity) => __awaiter(this, void 0, void 0, function* () {
|
|
86
85
|
try {
|
|
87
86
|
const dataItem = {
|
|
88
87
|
data: "",
|
|
@@ -98,7 +97,7 @@ export const WalletProvider = ({ children, }) => {
|
|
|
98
97
|
],
|
|
99
98
|
};
|
|
100
99
|
const signedDataItem = yield walletRef.current.signDataItem(dataItem);
|
|
101
|
-
const response = yield fetch(
|
|
100
|
+
const response = yield fetch(muUrl, {
|
|
102
101
|
method: "POST",
|
|
103
102
|
headers: {
|
|
104
103
|
"Content-Type": "application/octet-stream",
|
|
@@ -115,7 +114,7 @@ export const WalletProvider = ({ children, }) => {
|
|
|
115
114
|
throw error;
|
|
116
115
|
}
|
|
117
116
|
});
|
|
118
|
-
const sign = (transaction) => __awaiter(
|
|
117
|
+
const sign = (transaction) => __awaiter(this, void 0, void 0, function* () {
|
|
119
118
|
try {
|
|
120
119
|
return yield walletRef.current.sign(transaction);
|
|
121
120
|
}
|
|
@@ -124,21 +123,14 @@ export const WalletProvider = ({ children, }) => {
|
|
|
124
123
|
throw error;
|
|
125
124
|
}
|
|
126
125
|
});
|
|
127
|
-
return (React.createElement(
|
|
126
|
+
return (React.createElement(AOSyncContext.Provider, { value: {
|
|
128
127
|
isConnected,
|
|
129
128
|
connect,
|
|
130
129
|
disconnect,
|
|
131
|
-
getAllAddresses,
|
|
132
130
|
getAddress,
|
|
131
|
+
getAllAddresses,
|
|
133
132
|
sendAR,
|
|
134
133
|
signAOMessage,
|
|
135
134
|
sign,
|
|
136
135
|
} }, children));
|
|
137
|
-
}
|
|
138
|
-
export const useWallet = () => {
|
|
139
|
-
const context = useContext(WalletContext);
|
|
140
|
-
if (!context) {
|
|
141
|
-
throw new Error("useWallet must be used within a WalletProvider");
|
|
142
|
-
}
|
|
143
|
-
return context;
|
|
144
|
-
};
|
|
136
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vela-ventures/aosync-sdk-react",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -33,6 +33,30 @@
|
|
|
33
33
|
"react-dom": "^19.0.0",
|
|
34
34
|
"typescript": "^5.7.3"
|
|
35
35
|
},
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "git+https://github.com/vela-ventures/aosync-sdk-react.git"
|
|
39
|
+
},
|
|
40
|
+
"homepage": "https://github.com/vela-ventures/aosync-sdk-react",
|
|
41
|
+
"keywords": [
|
|
42
|
+
"arweave",
|
|
43
|
+
"arweave-js",
|
|
44
|
+
"arweave-sdk",
|
|
45
|
+
"ao",
|
|
46
|
+
"ao-sync",
|
|
47
|
+
"ao-sync-react",
|
|
48
|
+
"aosync-react",
|
|
49
|
+
"ao-sync-sdk",
|
|
50
|
+
"becon",
|
|
51
|
+
"beacon-wallet",
|
|
52
|
+
"react",
|
|
53
|
+
"web3",
|
|
54
|
+
"wallet",
|
|
55
|
+
"sdk",
|
|
56
|
+
"vela-ventures",
|
|
57
|
+
"wallet-sdk",
|
|
58
|
+
"@vela-ventures"
|
|
59
|
+
],
|
|
36
60
|
"license": "MIT",
|
|
37
61
|
"contributors": [
|
|
38
62
|
"Artem Purundzhian <artempa1607@gmail.com>"
|
|
@@ -41,6 +65,6 @@
|
|
|
41
65
|
"react": "^18.2.0"
|
|
42
66
|
},
|
|
43
67
|
"dependencies": {
|
|
44
|
-
"@vela-ventures/ao-sync-sdk": "^1.1.
|
|
68
|
+
"@vela-ventures/ao-sync-sdk": "^1.1.11"
|
|
45
69
|
}
|
|
46
70
|
}
|
package/dist/component.d.ts
DELETED
package/dist/component.js
DELETED
package/dist/component.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"component.js","sourceRoot":"","sources":["../src/component.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,MAAM,WAAW,GAAC,CAAC,KAAK,EAAC,EAAE;IACzB,MAAM,EAAC,KAAK,EAAC,GAAG,KAAK,CAAC;IACtB,OAAO,CACL;QACE,oCAAS,KAAK,CAAU,CACpB,CACP,CAAC;AACJ,CAAC,CAAA;AACD,eAAe,WAAW,CAAC"}
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,EAAE;IAC5B,OAAO,cAAc,CAAA;AACzB,CAAC,CAAA"}
|