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
Copy file name to clipboardexpand all lines: README.md
+59-16
Original file line number
Diff line number
Diff line change
@@ -24,7 +24,30 @@ We will keep improving this extension, and any suggestions are welcome!
24
24
25
25
Now WebExtensionApp supports two different ways to communicate with Dapp page.
26
26
27
-
#### 3.1 Using `postMessage`
27
+
28
+
#### 3.1 Using NebPay SDK
29
+
30
+
Please refer to Dapp Example [SuperDictionary](https://github.com/15010159959/super-dictionary) to learn how to use this extension.
31
+
32
+
When developing your Dapp page, you can use [NebPay SDK](https://github.com/nebulasio/nebPay) to communicate with ExtensionWallet. Just as the example below.
33
+
34
+
To call a SmartContract through extensionWallet, you should use [`nebpay.call`](https://github.com/nebulasio/nebPay/blob/master/doc/NebPay_Introduction.md#call) or [`nebpay.simulateCall`](https://github.com/nebulasio/nebPay/blob/master/doc/NebPay_Introduction.md#simulatecall) to send a transaction as below:
35
+
```js
36
+
nebPay.call(to, value, callFunction, callArgs, {
37
+
qrcode: {
38
+
showQRCode:true
39
+
},
40
+
listener: cbCallDapp //specify a listener to handle the transaction result
41
+
});
42
+
43
+
functioncbCallDapp(resp){
44
+
console.log("response: "+JSON.stringify(resp))
45
+
}
46
+
47
+
```
48
+
49
+
50
+
#### 3.2 Using `postMessage`
28
51
29
52
When developing your Dapp page, you can use `postMessage` API to communicate with ExtensionWallet, and use `window.addEventListener` to listen the message answer. Just as the example below.
Please refer to Dapp Example [SuperDictionary](https://github.com/15010159959/super-dictionary) to learn how to use this extension.
60
-
61
-
When developing your Dapp page, you can also use [NebPay SDK](https://github.com/nebulasio/nebPay) to communicate with ExtensionWallet. Just as the example below.
82
+
It is useful for Dapp to get the current account address in the extension. Here is the explanation on how to achive this.
62
83
63
-
To call a SmartContract through extensionWallet, you should use [`nebpay.call`](https://github.com/nebulasio/nebPay/blob/master/doc/NebPay_Introduction.md#call) or [`nebpay.simulateCall`](https://github.com/nebulasio/nebPay/blob/master/doc/NebPay_Introduction.md#simulatecall) to send a transaction as below:
84
+
Method 1:
64
85
```js
65
-
nebPay.call(to, value, callFunction, callArgs, {
66
-
qrcode: {
67
-
showQRCode:true
68
-
},
69
-
listener: cbCallDapp //specify a listener to handle the transaction result
70
-
});
71
-
72
-
functioncbCallDapp(resp){
73
-
console.log("response: "+JSON.stringify(resp))
86
+
var userAddrerss;
87
+
88
+
functiongetUserAddress() {
89
+
console.log("********* get account ************")
90
+
window.postMessage({
91
+
"target":"contentscript",
92
+
"data":{
93
+
},
94
+
"method":"getAccount",
95
+
}, "*");
96
+
}
97
+
// listen message from contentscript
98
+
window.addEventListener('message', function(e) {
99
+
// e.detail contains the transferred data (can
100
+
console.log("recived by page:"+ e +", e.data:"+JSON.stringify(e.data));
101
+
if (!!e.data.data.account) {
102
+
userAddrerss =e.data.data.account;
74
103
}
75
-
104
+
})
105
+
106
+
```
107
+
108
+
Method 2:
109
+
A module `NasExtWallet` is injected to your page if NasExtWallet is installed, then you can use the code below to get user account:
110
+
```js
111
+
var userAddrerss;
112
+
functioncallback(addr){
113
+
userAddrerss = addr;
114
+
}
115
+
116
+
NasExtWallet.getUserAddress(callback)
117
+
76
118
```
77
119
120
+
78
121
### example page
79
122
And you can use `example/TestPage.html` to take a test.
0 commit comments