@@ -4,9 +4,7 @@ Snippets of code that can be used to implement flows inside MiniPay
44
55## How to use
66
7- ### Check cUSD Balance of an address
8-
9- #### Using Ethers
7+ ### Check cUSD Balance of an address (Using Ethers)
108
119[ Code] ( ./ethers/checkCUSDBalance.js )
1210
@@ -16,7 +14,7 @@ const provider = new providers.JsonRpcProvider("https://forno.celo.org"); // Mai
1614let balance = await checkCUSDBalance (provider, address); // In Ether unit
1715```
1816
19- #### Using Viem
17+ ### Check cUSD Balance of an address ( Using Viem)
2018
2119[ Code] ( ./viem/checkCUSDBalance.js )
2220
@@ -29,9 +27,7 @@ const publicClient = createPublicClient({
2927let balance = await checkCUSDBalance (publicClient, address); // In Ether unit
3028```
3129
32- ### Check If a transaction succeeded
33-
34- #### Using Ethers
30+ ### Check If a transaction succeeded (Using Ethers)
3531
3632[ Code] ( ./ethers/checkIfTransactionSucceeded.js )
3733
@@ -44,7 +40,7 @@ let transactionStatus = await checkIfTransactionSucceeded(
4440);
4541```
4642
47- #### Using Viem
43+ ### Check If a transaction succeeded ( Using Viem)
4844
4945[ Code] ( ./viem/checkIfTransactionSucceeded.js )
5046
@@ -60,13 +56,11 @@ let transactionStatus = await checkIfTransactionSucceeded(
6056); // In Ether unit
6157```
6258
63- ### Estimate Gas for a transaction
64-
65- #### Using Ethers
59+ ### Estimate Gas for a transaction (Using Ethers)
6660
6761[ Code] ( ./ethers/estimateGas.js )
6862
69- ##### Estimate Gas in Celo
63+ #### Estimate Gas in Celo (Using Ethers)
7064
7165``` js
7266const provider = new providers.JsonRpcProvider (" https://forno.celo.org" ); // Mainnet
@@ -80,7 +74,7 @@ let gasLimit = await estimateGas(provider, {
8074});
8175```
8276
83- ##### Estimate Gas in cUSD
77+ #### Estimate Gas in cUSD (Using Ethers)
8478
8579``` js
8680const provider = new providers.JsonRpcProvider (" https://forno.celo.org" ); // Mainnet
@@ -100,11 +94,11 @@ let gasLimit = await estimateGas(
10094);
10195```
10296
103- #### Using Viem
97+ ### Estimate Gas for a transaction ( Using Viem)
10498
10599[ Code] ( ./viem/estimateGas.js )
106100
107- ##### Estimate Gas in Celo
101+ #### Estimate Gas in Celo (Using Viem)
108102
109103``` js
110104const publicClient = createPublicClient ({
@@ -120,7 +114,7 @@ let gasLimit = await estimateGas(publicClient, {
120114});
121115```
122116
123- ##### Estimate Gas in cUSD
117+ #### Estimate Gas in cUSD (Using Viem)
124118
125119``` js
126120const publicClient = createPublicClient ({
@@ -142,21 +136,19 @@ let gasLimit = await estimateGas(
142136);
143137```
144138
145- ### Estimate Gas Price for a transaction
146-
147- #### Using Ethers
139+ ### Estimate Gas Price for a transaction (Using Ethers)
148140
149141[ Code] ( ./ethers/estimateGasPrice.js )
150142
151- ##### Estimate Gas Price in Celo
143+ #### Estimate Gas Price in Celo (Using Ethers)
152144
153145``` js
154146const provider = new providers.JsonRpcProvider (" https://forno.celo.org" ); // Mainnet
155147
156148let gasPrice = await estimateGasPrice (provider);
157149```
158150
159- ##### Estimate Gas Price in cUSD
151+ #### Estimate Gas Price in cUSD (Using Ethers)
160152
161153``` js
162154const provider = new providers.JsonRpcProvider (" https://forno.celo.org" ); // Mainnet
@@ -166,9 +158,11 @@ const STABLE_TOKEN_ADDRESS = "0x765DE816845861e75A25fCA122bb6898B8B1282a";
166158let gasPrice = await estimateGasPrice (provider, STABLE_TOKEN_ADDRESS );
167159```
168160
169- #### Using Viem
161+ ### Estimate Gas Price for a transaction (Using Viem)
162+
163+ [ Code] ( ./viem/estimateGasPrice.js )
170164
171- ##### Estimate Gas Price in Celo
165+ #### Estimate Gas Price in Celo (Using Viem)
172166
173167``` js
174168const publicClient = createPublicClient ({
@@ -179,7 +173,7 @@ const publicClient = createPublicClient({
179173let gasPrice = await estimateGasPrice (publicClient);
180174```
181175
182- ##### Estimate Gas Price in cUSD
176+ #### Estimate Gas Price in cUSD (Using Viem)
183177
184178``` js
185179const publicClient = createPublicClient ({
@@ -192,13 +186,9 @@ const STABLE_TOKEN_ADDRESS = "0x765DE816845861e75A25fCA122bb6898B8B1282a";
192186let gasPrice = await estimateGasPrice (provider, STABLE_TOKEN_ADDRESS );
193187```
194188
195- ### Calculate cUSD to be spent for transaction fees
196-
197- #### Using Ethers
189+ ### Calculate cUSD to be spent for transaction fees (Using Ethers)
198190
199191``` js
200- const { formatEther } = require (" ethers/lib/utils" );
201-
202192const provider = new providers.JsonRpcProvider (" https://forno.celo.org" );
203193
204194const STABLE_TOKEN_ADDRESS = " 0x765DE816845861e75A25fCA122bb6898B8B1282a" ;
@@ -221,11 +211,9 @@ let transactionFeesInCUSD = formatEther(
221211);
222212```
223213
224- #### Using Viem
214+ #### Calculate cUSD to be spent for transaction fees ( Using Viem)
225215
226216``` js
227- const { formatEther } = require (" viem" );
228-
229217const publicClient = createPublicClient ({
230218 chain: celo,
231219 transport: http (),
@@ -249,6 +237,220 @@ let gasPrice = await estimateGasPrice(publicClient, STABLE_TOKEN_ADDRESS);
249237let transactionFeesInCUSD = formatEther (gasLimit * hexToBigInt (gasPrice));
250238```
251239
240+ #### Lookup phone number registered under MiniPay issuer (Using Ethers)
241+
242+ [ Code] ( ./ethers/SocialConnect/index.js )
243+
244+ ``` js
245+ let wallet = new Wallet (process .env .ISSUER_PRIVATE_KEY , provider);
246+
247+ const issuer = new SocialConnectIssuer (wallet, {
248+ authenticationMethod: AuthenticationMethod .ENCRYPTION_KEY ,
249+ rawKey: process .env .DEK_PRIVATE_KEY ,
250+ });
251+
252+ await issuer .initialize ();
253+
254+ const identifierType = IdentifierPrefix .PHONE_NUMBER ;
255+
256+ /**
257+ * Any phone number you want to lookup
258+ *
259+ * The below phone number is registered on the testnet issuer mentioned below.
260+ */
261+ const identifier = " +911234567890" ;
262+
263+ /**
264+ * You can lookup under multiple issuers in one request.
265+ *
266+ * Below is the MiniPay issuer address on Mainnet.
267+ *
268+ * Note: Remember to make your environment variable ENVIRONMENT=MAINNET
269+ */
270+ let issuerAddresses = [" 0x7888612486844Bb9BE598668081c59A9f7367FBc" ];
271+
272+ // A testnet issuer we setup for you to lookup on testnet.
273+ // let issuerAddresses = ["0xDF7d8B197EB130cF68809730b0D41999A830c4d7"];
274+
275+ let results = await issuer .lookup (identifier, identifierType, issuerAddresses);
276+ ```
277+
278+ #### Lookup phone number registered under MiniPay issuer (Using Viem)
279+
280+ [ Code] ( ./viem/SocialConnect/index.js )
281+
282+ ``` js
283+ let account = privateKeyToAccount (process .env .ISSUER_PRIVATE_KEY );
284+
285+ let walletClient = createWalletClient ({
286+ account,
287+ transport: http (),
288+ chain,
289+ });
290+
291+ const issuer = new SocialConnectIssuer (walletClient, {
292+ authenticationMethod: AuthenticationMethod .ENCRYPTION_KEY ,
293+ rawKey: process .env .DEK_PRIVATE_KEY ,
294+ });
295+
296+ await issuer .initialize ();
297+
298+ const identifierType = IdentifierPrefix .PHONE_NUMBER ;
299+
300+ /**
301+ * Any phone number you want to lookup
302+ *
303+ * The below phone number is registered on the testnet issuer mentioned below.
304+ */
305+ const identifier = " +911234567890" ;
306+
307+ /**
308+ * You can lookup under multiple issuers in one request.
309+ *
310+ * Below is the MiniPay issuer address on Mainnet.
311+ *
312+ * Note: Remember to make your environment variable ENVIRONMENT=MAINNET
313+ */
314+ let issuerAddresses = [" 0x7888612486844Bb9BE598668081c59A9f7367FBc" ];
315+
316+ // A testnet issuer we setup for you to lookup on testnet.
317+ // let issuerAddresses = ["0xDF7d8B197EB130cF68809730b0D41999A830c4d7"];
318+
319+ let results = await issuer .lookup (identifier, identifierType, issuerAddresses);
320+ ```
321+
322+ #### Registering phone number using your own issuer (Using Ethers)
323+
324+ [ Code] ( ./ethers/SocialConnect/index.js )
325+
326+ ``` js
327+ let wallet = new Wallet (process .env .ISSUER_PRIVATE_KEY , provider);
328+
329+ const issuer = new SocialConnectIssuer (wallet, {
330+ authenticationMethod: AuthenticationMethod .ENCRYPTION_KEY ,
331+ rawKey: process .env .DEK_PRIVATE_KEY ,
332+ });
333+
334+ await issuer .initialize ();
335+
336+ const identifierType = IdentifierPrefix .PHONE_NUMBER ;
337+
338+ /**
339+ * Any phone number you want to register
340+ */
341+ const identifier = " +911234567890" ;
342+
343+ let addressToRegister = " <USER_ADDRESS>" ;
344+
345+ let results = await issuer .registerOnChainIdentifier (
346+ identifier,
347+ identifierType,
348+ addressToRegister
349+ );
350+ ```
351+
352+ #### Registering phone number using your own issuer (Using Viem)
353+
354+ [ Code] ( ./viem/SocialConnect/index.js )
355+
356+ ``` js
357+ let account = privateKeyToAccount (process .env .ISSUER_PRIVATE_KEY );
358+
359+ let walletClient = createWalletClient ({
360+ account,
361+ transport: http (),
362+ chain,
363+ });
364+
365+ const issuer = new SocialConnectIssuer (walletClient, {
366+ authenticationMethod: AuthenticationMethod .ENCRYPTION_KEY ,
367+ rawKey: process .env .DEK_PRIVATE_KEY ,
368+ });
369+
370+ await issuer .initialize ();
371+
372+ const identifierType = IdentifierPrefix .PHONE_NUMBER ;
373+
374+ /**
375+ * Any phone number you want to register
376+ */
377+ const identifier = " +911234567890" ;
378+
379+ let addressToRegister = " <USER_ADDRESS>" ;
380+
381+ let results = await issuer .registerOnChainIdentifier (
382+ identifier,
383+ identifierType,
384+ addressToRegister
385+ );
386+ ```
387+
388+ #### De-Registering phone number registered under your own issuer (Using Ethers)
389+
390+ [ Code] ( ./ethers/SocialConnect/index.js )
391+
392+ ``` js
393+ let wallet = new Wallet (process .env .ISSUER_PRIVATE_KEY , provider);
394+
395+ const issuer = new SocialConnectIssuer (wallet, {
396+ authenticationMethod: AuthenticationMethod .ENCRYPTION_KEY ,
397+ rawKey: process .env .DEK_PRIVATE_KEY ,
398+ });
399+
400+ await issuer .initialize ();
401+
402+ const identifierType = IdentifierPrefix .PHONE_NUMBER ;
403+
404+ /**
405+ * Any phone number you want to de-register
406+ */
407+ const identifier = " +911234567890" ;
408+
409+ let addressToDeRegister = " <USER_ADDRESS>" ;
410+
411+ let results = await issuer .deregisterOnChainIdentifier (
412+ identifier,
413+ identifierType,
414+ addressToDeRegister
415+ );
416+ ```
417+
418+ #### DeRegistering phone number registered under your own issuer (Using Viem)
419+
420+ [ Code] ( ./viem/SocialConnect/index.js )
421+
422+ ``` js
423+ let account = privateKeyToAccount (process .env .ISSUER_PRIVATE_KEY );
424+
425+ let walletClient = createWalletClient ({
426+ account,
427+ transport: http (),
428+ chain,
429+ });
430+
431+ const issuer = new SocialConnectIssuer (walletClient, {
432+ authenticationMethod: AuthenticationMethod .ENCRYPTION_KEY ,
433+ rawKey: process .env .DEK_PRIVATE_KEY ,
434+ });
435+
436+ await issuer .initialize ();
437+
438+ const identifierType = IdentifierPrefix .PHONE_NUMBER ;
439+
440+ /**
441+ * Any phone number you want to de-register
442+ */
443+ const identifier = " +911234567890" ;
444+
445+ let addressToDeRegister = " <USER_ADDRESS>" ;
446+
447+ let results = await issuer .deregisterOnChainIdentifier (
448+ identifier,
449+ identifierType,
450+ addressToDeRegister
451+ );
452+ ```
453+
252454## Support
253455
254456Please open issue on this repo.
0 commit comments