ryt-sdk 1.0.10 → 1.0.12

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 CHANGED
@@ -33,7 +33,156 @@ or
33
33
 
34
34
  <br>
35
35
 
36
- ### 🔐 Environment Setup
36
+ ### 🌐 Frontend Dapp Setup (Browser Mode)
37
+
38
+ <br>
39
+
40
+ RYT SDK supports browser-based dApps using injected wallets such as:
41
+
42
+ - MetaMask
43
+ - Rabby
44
+ - Coinbase Wallet
45
+
46
+ No private keys are required in frontend mode.
47
+
48
+ <br>
49
+
50
+ ### 💻 Frontend Example Dapp
51
+
52
+ <br>
53
+
54
+ ```javascript
55
+
56
+ import { useState } from "react";
57
+
58
+ import {
59
+ RYTContract,
60
+ RYTWallet,
61
+ hasRYT,
62
+ requestAccounts,
63
+ RYTProvider,
64
+ parseTokenUnits,
65
+ } from "ryt-sdk";
66
+
67
+ const CONTRACT_ADDRESS = process.env.ERC20_ADDRESS; /* deploy erc20 token */
68
+ const CHAIN_ID= process.env.CHAIN_ID; /* provide chain id */
69
+
70
+ const ABI = [
71
+ "function approve(address spender, uint256 value) returns (bool)",
72
+ "function transfer(address to, uint256 value) returns (bool)",
73
+ "function decimals() view returns (uint8)",
74
+ ];
75
+
76
+ function App() {
77
+ const [account, setAccount] = useState<string | null>(null);
78
+ const [contract, setContract] = useState<RYTContract | null>(null);
79
+
80
+ const [recipient, setRecipient] = useState("");
81
+ const [amount, setAmount] = useState("");
82
+ const [spender, setSpender] = useState("");
83
+ const [loading, setLoading] = useState(false);
84
+ const [txHash, setTxHash] = useState<string | null>(null);
85
+
86
+ /**
87
+ * Connect wallet using RTY SDK
88
+ */
89
+ const connectWallet = async () => {
90
+ try {
91
+ if (!hasRYT()) {
92
+ alert("Install MetaMask or compatible wallet");
93
+ return;
94
+ }
95
+
96
+ setLoading(true);
97
+
98
+ // 1. request accounts via SDK
99
+ const accounts = await requestAccounts();
100
+ const address = accounts[0];
101
+
102
+ // 2. create provider via SDK
103
+ const provider = new RYTProvider({
104
+ chainId: CHAIN_ID,
105
+ rpcUrls: [process.env.RPC_URL] /* provide rpc url */
106
+ });
107
+
108
+ // 3. create wallet
109
+ const signer = await provider.getSigner();
110
+ const wallet = new RYTWallet(signer);
111
+
112
+ // 4. create contract instance via SDK
113
+ const rytContract = new RYTContract(
114
+ CONTRACT_ADDRESS,
115
+ ABI,
116
+ wallet
117
+ );
118
+
119
+ setAccount(address);
120
+ setContract(rytContract);
121
+ } catch (err) {
122
+ console.error(err);
123
+ } finally {
124
+ setLoading(false);
125
+ }
126
+ };
127
+
128
+ /**
129
+ * Approve tokens
130
+ */
131
+ const handleApprove = async () => {
132
+ if (!contract) return alert("Connect wallet");
133
+
134
+ try {
135
+ setLoading(true);
136
+
137
+ const decimals = await contract.read("decimals");
138
+
139
+ const parsed = parseTokenUnits(amount, decimals);
140
+
141
+ const tx = await contract.write("approve", spender, parsed);
142
+
143
+ setTxHash(tx.hash);
144
+ await tx.wait();
145
+ } finally {
146
+ setLoading(false);
147
+ }
148
+ };
149
+
150
+ /**
151
+ * Transfer tokens
152
+ */
153
+ const handleTransfer = async () => {
154
+ if (!contract) return alert("Connect wallet");
155
+
156
+ try {
157
+ setLoading(true);
158
+
159
+ const decimals = await contract.read("decimals");
160
+
161
+ const parsed = parseTokenUnits(amount, decimals);
162
+
163
+ const tx = await contract.write("transfer", recipient, parsed);
164
+
165
+ setTxHash(tx.hash);
166
+ await tx.wait();
167
+ } finally {
168
+ setLoading(false);
169
+ }
170
+ };
171
+
172
+ return (/* Build your stunning UI here*/);
173
+ }
174
+
175
+ export default App;
176
+
177
+ ```
178
+
179
+ <br>
180
+
181
+ ### ⚡ Backend Quickstart Guide
182
+
183
+ <br>
184
+
185
+ #### 🔐 Environment Setup
37
186
 
38
187
  <br>
39
188
 
@@ -55,13 +204,18 @@ MATH_LIB_ADDRESS=0xLibraryAddress
55
204
 
56
205
  <br>
57
206
 
58
- ### 30-Second Quickstart
207
+ #### 💻 Code Example
208
+
59
209
  <br>
60
210
 
211
+
61
212
  ```javascript
62
- import RYTProvider from "ryt-sdk/provider";
63
- import RYTWallet from "ryt-sdk/wallet";
64
- import RYTContract from "ryt-sdk/contract";
213
+
214
+ import {
215
+ RYTContract,
216
+ RYTWallet,
217
+ RYTProvider
218
+ } from "ryt-sdk";
65
219
 
66
220
  const provider = new RYTProvider({
67
221
  chainId: process.env.CHAIN_ID,
package/dist/contract.js CHANGED
@@ -1,6 +1,78 @@
1
1
  import { ethers } from "ethers";
2
2
  import RYTWallet from "./wallet";
3
- import ERC1967Proxy from "@openzeppelin/contracts/build/contracts/ERC1967Proxy.json";
3
+ const ERC1967_PROXY_ABI = [
4
+ {
5
+ "inputs": [
6
+ {
7
+ "internalType": "address",
8
+ "name": "implementation",
9
+ "type": "address"
10
+ },
11
+ {
12
+ "internalType": "bytes",
13
+ "name": "_data",
14
+ "type": "bytes"
15
+ }
16
+ ],
17
+ "stateMutability": "payable",
18
+ "type": "constructor"
19
+ },
20
+ {
21
+ "inputs": [
22
+ {
23
+ "internalType": "address",
24
+ "name": "target",
25
+ "type": "address"
26
+ }
27
+ ],
28
+ "name": "AddressEmptyCode",
29
+ "type": "error"
30
+ },
31
+ {
32
+ "inputs": [
33
+ {
34
+ "internalType": "address",
35
+ "name": "implementation",
36
+ "type": "address"
37
+ }
38
+ ],
39
+ "name": "ERC1967InvalidImplementation",
40
+ "type": "error"
41
+ },
42
+ {
43
+ "inputs": [],
44
+ "name": "ERC1967NonPayable",
45
+ "type": "error"
46
+ },
47
+ {
48
+ "inputs": [],
49
+ "name": "ERC1967ProxyUninitialized",
50
+ "type": "error"
51
+ },
52
+ {
53
+ "inputs": [],
54
+ "name": "FailedCall",
55
+ "type": "error"
56
+ },
57
+ {
58
+ "anonymous": false,
59
+ "inputs": [
60
+ {
61
+ "indexed": true,
62
+ "internalType": "address",
63
+ "name": "implementation",
64
+ "type": "address"
65
+ }
66
+ ],
67
+ "name": "Upgraded",
68
+ "type": "event"
69
+ },
70
+ {
71
+ "stateMutability": "payable",
72
+ "type": "fallback"
73
+ }
74
+ ];
75
+ const ERC1967_PROXY_BYTECODE = "0x60806040526040516103b63803806103b683398101604081905261002291610238565b8051610041576040516330a289cf60e21b815260040160405180910390fd5b61004b8282610052565b5050610307565b61005b826100b0565b6040516001600160a01b038316907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b905f90a28051156100a45761009f828261012b565b505050565b6100ac6101cc565b5050565b806001600160a01b03163b5f036100ea57604051634c9c8ce360e01b81526001600160a01b03821660048201526024015b60405180910390fd5b7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc80546001600160a01b0319166001600160a01b0392909216919091179055565b60605f61013884846101ed565b905080801561015957505f3d118061015957505f846001600160a01b03163b115b1561016e57610166610200565b9150506101c6565b801561019857604051639996b31560e01b81526001600160a01b03851660048201526024016100e1565b3d156101ab576101a6610219565b6101c4565b60405163d6bda27560e01b815260040160405180910390fd5b505b92915050565b34156101eb5760405163b398979f60e01b815260040160405180910390fd5b565b5f5f5f835160208501865af49392505050565b6040513d81523d5f602083013e3d602001810160405290565b6040513d5f823e3d81fd5b634e487b7160e01b5f52604160045260245ffd5b5f5f60408385031215610249575f5ffd5b82516001600160a01b038116811461025f575f5ffd5b60208401519092506001600160401b0381111561027a575f5ffd5b8301601f8101851361028a575f5ffd5b80516001600160401b038111156102a3576102a3610224565b604051601f8201601f19908116603f011681016001600160401b03811182821017156102d1576102d1610224565b6040528181528282016020018710156102e8575f5ffd5b8160208401602083015e5f602083830101528093505050509250929050565b60a3806103135f395ff3fe6080604052600a600c565b005b60186014601a565b6050565b565b5f604b7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc546001600160a01b031690565b905090565b365f5f375f5f365f845af43d5f5f3e8080156069573d5ff35b3d5ffdfea26469706673582212200f18014ea5c0066d8797ddb2f8a13e8798e6d2e79c2d6de92e1ead588a58c3b764736f6c634300081f0033"; // (full bytecode)
4
76
  /**
5
77
  * -----------------------------
6
78
  * Internal helper: Link libraries into bytecode
@@ -191,7 +263,7 @@ export default class RYTContract {
191
263
  const impl = await implFactory.deploy();
192
264
  await impl.waitForDeployment();
193
265
  const implAddress = impl.target;
194
- const proxyFactory = new ethers.ContractFactory(ERC1967Proxy.abi, ERC1967Proxy.bytecode, signer);
266
+ const proxyFactory = new ethers.ContractFactory(ERC1967_PROXY_ABI, ERC1967_PROXY_BYTECODE, signer);
195
267
  const proxy = await proxyFactory.deploy(implAddress, options.initData ?? "0x");
196
268
  await proxy.waitForDeployment();
197
269
  return new RYTContract(proxy.target, options.implementationAbi, this.wallet);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ryt-sdk",
3
3
  "type": "module",
4
- "version": "1.0.10",
4
+ "version": "1.0.12",
5
5
  "description": "RYT blockchain SDK for provider, wallet, and smart contract interactions",
6
6
  "author": "Muhammad Hammad Mubeen",
7
7
  "license": "MIT",
@@ -46,8 +46,6 @@
46
46
  "ethers": "^6.8.0"
47
47
  },
48
48
  "devDependencies": {
49
- "@openzeppelin/contracts": "^5.4.0",
50
- "@openzeppelin/contracts-upgradeable": "^5.4.0",
51
49
  "@types/node": "^20.0.0",
52
50
  "eslint": "^8.0.0",
53
51
  "prettier": "^2.8.0",