You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## Calling web3 functions through the social connect
41
34
42
-
Since the Metamask gets connected to the social connect, all web3 calls also need to be done through the social connect.
43
-
You can use the following functions to call the blockchain layer:
35
+
### Options
36
+
There are two fields in the options object.
37
+
`clientId` is the id that's specific to your application. If you use an empty clientId, it will pick up the default settings. However, if you want to customize the widget according to your own needs, then refer our [docs](https://docs.plurality.network) to find out the way to get your own clientId.
38
+
`theme` can be either light or dark
39
+
40
+
41
+
## Calling web3 functions through the Smart Profile Wallet
42
+
43
+
Every web3 login solution needs to interact with the blockchain for carrying out various functions. Once the widget is embedded and the user connects their profile and a session is stored in the local storage, then plurality’s wallet solution provides the following standard web3 functions. To call them in your application, use the following code samples
44
+
44
45
45
46
### Get All Connected Accounts
46
47
Returns all accounts that have been connected through the social connect
47
48
```
48
-
PluralitySocialConnect.getAllAccounts()
49
+
(await PluralitySocialConnect.getAllAccounts()) as AllAccountsDataType;
49
50
Returns: [0x123…, 0x456…]
50
51
```
51
52
52
53
### Get Current Connected Account
53
54
Get current account connected to the social connect
54
55
```
55
-
PluralitySocialConnect.getConnectedAccount()
56
+
(await PluralitySocialConnect.getConnectedAccount()) as ConnectedAccountDataType;
56
57
Returns: 0x123…
57
58
```
58
59
59
60
### Get Signature
60
61
Gets the message signed using the connected account and returns the signature
(await PluralitySocialConnect.verifyMessageSignature(message, key)) as VerifySignedMessageDataType;
72
70
```
73
71
### Get Balance
74
72
Returns balance of the current account in wei. You need to convert it to required denomination yourself
75
73
```
76
-
PluralitySocialConnect.getBalance()
74
+
(await PluralitySocialConnect.getBalance(rpc, chainId)) as GetBalanceDataType;
77
75
```
78
76
79
77
### Send Transaction
80
-
Send a certain amount (in ethers) to a certain address. Returns the transaction object
78
+
Send a certain amount (in ethers) to a certain address. Returns the transaction object.
79
+
80
+
Please note that since Plurality profiles are chain agnostic, you need to provide the RPC and the chainId to ensure that balance is being read from the current read. You can find the RPC and the chainId of your preferred chain from [here](https://chainlist.org/)
(await PluralitySocialConnect.sendTransaction(rawTx, rpc, chainId)) as SendTransactionDataType;
84
84
```
85
85
86
86
### Get Block Number
87
-
Returns the latest block number
87
+
Returns the latest block number. Please note that since Plurality profiles are chain agnostic, you need to provide the RPC and the chainId to ensure that balance is being read from the current read. You can find the RPC and the chainId of your preferred chain from [here](https://chainlist.org/)
88
+
88
89
```
89
-
PluralitySocialConnect.getBlockNumber()
90
+
(await PluralitySocialConnect.getBlockNumber(rpc, chainId)) as GetBlockNumberDataType;
90
91
```
91
92
92
93
### Get Transaction Count
93
94
Returns the transaction count of the given address
const abi = '[{"inputs":[],"name":"retrieve","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"num","type":"uint256"}],"name":"store","outputs":[],"stateMutability":"nonpayable","type":"function"}]';
const abi = '[{"inputs":[],"name":"retrieve","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"num","type":"uint256"}],"name":"store","outputs":[],"stateMutability":"nonpayable","type":"function"}]';
(await PluralitySocialConnect.writeToContract(address, abiVal, action, params, rpc, chainId, options)) as WriteToContractDataType;
109
+
```
110
+
111
+
## Calling profile functions through the Smart Profile Wallet
112
+
Each wallet created through this embedded widget has a profile attached to it which contains basic user information like name, bio, avatar and description. Moreover, it also has the user's interests & reputation which is analysed from the social accounts connected to that profile.
113
+
114
+
As an application developer, you can get profile data from the connected wallet.
115
+
116
+
Every time the user does a successful login, you will get a response in the data handler that’s attached to the embedded widget
However, if you want to fetch the smart profile data at any point later, you can use the following function.
131
+
132
+
### Get Smart Profile Data
133
+
```
134
+
(await PluralitySocialConnect.getSmartProfileData()) as ConnectedAccountDataType;
135
+
```
136
+
137
+
### Set Public Data
138
+
139
+
As a decentralized application developer, you might also need to store user’s information in a verifiable, decentralized, but gasless and privacy-preserving way. If you want to store any information about the user derived from their actions on your platform, you can set that information in your user’s profile. Next time when the user logs in to this dApp again, then the application will have access to this data again.
140
+
141
+
```
142
+
(await PluralitySocialConnect.setPublicData("key", "value")) as ConnectedAccountDataType;
143
+
```
144
+
### Get Public Data
145
+
To get previously stored data, the application can get it using the following function
146
+
147
+
```
148
+
(await PluralitySocialConnect.getPublicData("name")) as ConnectedAccountDataType;
149
+
```
150
+
151
+
### Set Private Data
152
+
153
+
Since user profiles are shared amongst different apps and platforms, if an application wants to ensure that the data you put in your user’s profile cannot be seen by any other application, then the application needs to set it in a private way.
154
+
155
+
```
156
+
(await PluralitySocialConnect.setPrivateData("work", "Plurality")) as ConnectedAccountDataType;
157
+
```
158
+
159
+
### Get Private Data
160
+
161
+
To get previously stored data, the application can get it using the following function
162
+
163
+
```
164
+
(await PluralitySocialConnect.getPrivateData("work")) as ConnectedAccountDataType;
0 commit comments