index.vue 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  1. <script setup lang="ts">
  2. /* Import modules. */
  3. import { ethers } from 'ethers'
  4. import numeral from 'numeral'
  5. import {
  6. getOutpoint,
  7. getTip,
  8. } from '@nexajs/rostrum'
  9. /* Configure meta tags. */
  10. useHead({
  11. title: 'Nexa — APECS Dev',
  12. meta: [
  13. { name: 'description', content: 'Nexa toolkit.' }
  14. ],
  15. })
  16. const rostrumSearchVal = ref(null)
  17. const searchType = ref(null)
  18. const account = ref(null)
  19. const blockHeight = ref(null)
  20. const blocks = ref(null)
  21. const debugCode = ref(null)
  22. const searchRostrum = async () => {
  23. console.log('Searching', searchType.value, ' for ->', rostrumSearchVal.value)
  24. const result = await getOutpoint(rostrumSearchVal.value)
  25. .catch(err => console.error(err))
  26. console.log('SEARCH RESULT', result)
  27. debugCode.value = JSON.stringify(result, null, 2)
  28. }
  29. // NOTE: Should ONLY be run on the client.
  30. if (process.client) {
  31. const es = new EventSource('https://mempool.nexa.sh')
  32. // console.log('EVENT SOURCE', es)
  33. es.onmessage = function (event) {
  34. // console.log('ES DATA', typeof event.data, event.data)
  35. try {
  36. const formatted = JSON.stringify(
  37. JSON.parse(event.data), null, 2)
  38. console.log('MEMPOOL', formatted)
  39. debugCode.value = formatted
  40. } catch (err) {
  41. console.error(err)
  42. }
  43. }
  44. }
  45. const init = async () => {
  46. const tip = await getTip()
  47. .catch(err => console.error(err))
  48. console.log('TIP', tip)
  49. /* Set block height. */
  50. blockHeight.value = tip.height
  51. }
  52. onMounted(() => {
  53. init()
  54. })
  55. </script>
  56. <template>
  57. <!-- <main class="relative min-h-screen bg-gray-100"> -->
  58. <main class="py-8 overflow-x-hidden overflow-y-hidden bg-gradient-to-r from-yellow-600 to-yellow-400">
  59. <div class="max-w-3xl mx-auto px-4 sm:px-6 lg:max-w-7xl lg:px-8">
  60. <h1 class="sr-only">Profile</h1>
  61. <!-- Main 3 column grid -->
  62. <div class="grid grid-cols-1 gap-4 items-start lg:grid-cols-3 lg:gap-8">
  63. <!-- Left column -->
  64. <div class="grid grid-cols-1 gap-4 lg:col-span-2">
  65. <!-- Welcome panel -->
  66. <section aria-labelledby="profile-overview-title">
  67. <div class="rounded-lg bg-white overflow-hidden shadow">
  68. <h2 class="sr-only" id="profile-overview-title">Profile Overview</h2>
  69. <div class="bg-white p-6">
  70. <div class="sm:flex sm:items-center sm:justify-between">
  71. <div class="sm:flex sm:space-x-5">
  72. <div class="p-3 flex-shrink-0 border-2 border-yellow-500 rounded-full shadow-lg">
  73. <img
  74. class="h-20 w-20"
  75. src="~/assets/img/logos/NEXA.svg"
  76. alt=""
  77. />
  78. </div>
  79. <div class="mt-4 text-center sm:mt-0 sm:pt-1 sm:text-left">
  80. <p class="text-sm font-medium text-gray-600">
  81. Connected to Mainnet
  82. </p>
  83. <p class="text-xl font-bold text-gray-900 sm:text-2xl">
  84. Nexa
  85. </p>
  86. <p class="text-sm font-medium text-gray-600">
  87. {{account}}
  88. </p>
  89. </div>
  90. </div>
  91. <div class="mt-5 flex justify-center sm:mt-0">
  92. <a @click="testMetaMask" href="javascript://" class="flex justify-center items-center px-4 py-2 border border-gray-300 shadow-sm text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50">
  93. Test MetaMask
  94. </a>
  95. <a @click="testSigning" href="javascript://" class="flex justify-center items-center px-4 py-2 border border-gray-300 shadow-sm text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50">
  96. Test Signing
  97. </a>
  98. </div>
  99. </div>
  100. </div>
  101. <div class="border-t border-gray-200 bg-gray-50 grid grid-cols-1 divide-y divide-gray-200 sm:grid-cols-3 sm:divide-y-0 sm:divide-x">
  102. <div class="px-6 py-5 text-sm font-medium text-center">
  103. <span class="block text-gray-600">Latest Block Height</span>
  104. <span class="block text-gray-900">{{displayBlockHeight}}</span>
  105. </div>
  106. <div class="px-6 py-5 text-sm font-medium text-center">
  107. <span class="block text-gray-600">Last Block Validator</span>
  108. <span class="block text-gray-900">n/a</span>
  109. </div>
  110. <div class="px-6 py-5 text-sm font-medium text-center">
  111. <span class="block text-gray-600">Next Difficulty Adjustment</span>
  112. <span class="block text-gray-900">n/a</span>
  113. </div>
  114. </div>
  115. </div>
  116. </section>
  117. <section class="p-3 flex flex-col gap-4 bg-gradient-to-r from-gray-100 to-gray-300 border-2 border-gray-400 rounded-lg shadow-md">
  118. <h2 class="text-2xl font-medium">
  119. Rostrum Search
  120. </h2>
  121. <select v-model="searchType" class="my-3 px-2 py-2 text-xl text-indigo-50 font-medium bg-gray-700 rounded-lg shadow-md">
  122. <option>Choose a command:</option>
  123. <option value="outpoint">Outpoint</option>
  124. <option value="token">Token</option>
  125. </select>
  126. <input
  127. type="text"
  128. class="px-3 py-2 bg-yellow-100 border-2 border-yellow-400 rounded-lg shadow-md"
  129. v-model="rostrumSearchVal"
  130. />
  131. <button
  132. @click="searchRostrum"
  133. class="py-2 bg-blue-500 border-2 border-blue-700 rounded-lg shadow-md"
  134. >
  135. <span class="text-xl text-blue-50 font-medium">
  136. Search Rostrum
  137. </span>
  138. </button>
  139. </section>
  140. <section class="bg-gradient-to-r from-yellow-100 to-yellow-200 border-2 border-yellow-500 rounded-xl shadow-md">
  141. <pre
  142. v-html="debugCode"
  143. class="px-5 py-3 text-yellow-900"
  144. />
  145. </section>
  146. <!-- Actions panel -->
  147. <section aria-labelledby="quick-links-title">
  148. <div class="rounded-lg bg-gray-200 overflow-hidden shadow divide-y divide-gray-200 sm:divide-y-0 sm:grid sm:grid-cols-2 sm:gap-px">
  149. <h2 class="sr-only" id="quick-links-title">Quick links</h2>
  150. <div class="rounded-tl-lg rounded-tr-lg sm:rounded-tr-none relative group bg-white p-6 focus-within:ring-2 focus-within:ring-inset focus-within:ring-cyan-500">
  151. <div>
  152. <span class="rounded-lg inline-flex p-3 bg-teal-50 text-teal-700 ring-4 ring-white">
  153. <!-- Heroicon name: outline/clock -->
  154. <svg class="h-6 w-6" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" aria-hidden="true">
  155. <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z" />
  156. </svg>
  157. </span>
  158. </div>
  159. <div class="mt-8">
  160. <h3 class="text-lg font-medium">
  161. <a href="javascript://" class="focus:outline-none">
  162. <!-- Extend touch target to entire panel -->
  163. <span class="absolute inset-0" aria-hidden="true"></span>
  164. Getting Started
  165. </a>
  166. </h3>
  167. <p class="mt-2 text-sm text-gray-500">
  168. Doloribus dolores nostrum quia qui natus officia quod et dolorem. Sit repellendus qui ut at blanditiis et quo et molestiae.
  169. </p>
  170. </div>
  171. <span class="pointer-events-none absolute top-6 right-6 text-gray-300 group-hover:text-gray-400" aria-hidden="true">
  172. <svg class="h-6 w-6" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 24 24">
  173. <path
  174. d="M20 4h1a1 1 0 00-1-1v1zm-1 12a1 1 0 102 0h-2zM8 3a1 1 0 000 2V3zM3.293 19.293a1 1 0 101.414 1.414l-1.414-1.414zM19 4v12h2V4h-2zm1-1H8v2h12V3zm-.707.293l-16 16 1.414 1.414 16-16-1.414-1.414z"
  175. />
  176. </svg>
  177. </span>
  178. </div>
  179. <div class="sm:rounded-tr-lg relative group bg-white p-6 focus-within:ring-2 focus-within:ring-inset focus-within:ring-cyan-500">
  180. <div>
  181. <span class="rounded-lg inline-flex p-3 bg-purple-50 text-purple-700 ring-4 ring-white">
  182. <!-- Heroicon name: outline/badge-check -->
  183. <svg class="h-6 w-6" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" aria-hidden="true">
  184. <path
  185. stroke-linecap="round"
  186. stroke-linejoin="round"
  187. stroke-width="2"
  188. d="M9 12l2 2 4-4M7.835 4.697a3.42 3.42 0 001.946-.806 3.42 3.42 0 014.438 0 3.42 3.42 0 001.946.806 3.42 3.42 0 013.138 3.138 3.42 3.42 0 00.806 1.946 3.42 3.42 0 010 4.438 3.42 3.42 0 00-.806 1.946 3.42 3.42 0 01-3.138 3.138 3.42 3.42 0 00-1.946.806 3.42 3.42 0 01-4.438 0 3.42 3.42 0 00-1.946-.806 3.42 3.42 0 01-3.138-3.138 3.42 3.42 0 00-.806-1.946 3.42 3.42 0 010-4.438 3.42 3.42 0 00.806-1.946 3.42 3.42 0 013.138-3.138z"
  189. />
  190. </svg>
  191. </span>
  192. </div>
  193. <div class="mt-8">
  194. <h3 class="text-lg font-medium">
  195. <NuxtLink to="/smartbch/contracts" class="focus:outline-none">
  196. <!-- Extend touch target to entire panel -->
  197. <span class="absolute inset-0" aria-hidden="true"></span>
  198. Notable Contracts
  199. </NuxtLink>
  200. </h3>
  201. <p class="mt-2 text-sm text-gray-500">
  202. Doloribus dolores nostrum quia qui natus officia quod et dolorem. Sit repellendus qui ut at blanditiis et quo et molestiae.
  203. </p>
  204. </div>
  205. <span class="pointer-events-none absolute top-6 right-6 text-gray-300 group-hover:text-gray-400" aria-hidden="true">
  206. <svg class="h-6 w-6" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 24 24">
  207. <path
  208. d="M20 4h1a1 1 0 00-1-1v1zm-1 12a1 1 0 102 0h-2zM8 3a1 1 0 000 2V3zM3.293 19.293a1 1 0 101.414 1.414l-1.414-1.414zM19 4v12h2V4h-2zm1-1H8v2h12V3zm-.707.293l-16 16 1.414 1.414 16-16-1.414-1.414z"
  209. />
  210. </svg>
  211. </span>
  212. </div>
  213. <div class="relative group bg-white p-6 focus-within:ring-2 focus-within:ring-inset focus-within:ring-cyan-500">
  214. <div>
  215. <span class="rounded-lg inline-flex p-3 bg-sky-50 text-sky-700 ring-4 ring-white">
  216. <!-- Heroicon name: outline/users -->
  217. <svg class="h-6 w-6" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" aria-hidden="true">
  218. <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4.354a4 4 0 110 5.292M15 21H3v-1a6 6 0 0112 0v1zm0 0h6v-1a6 6 0 00-9-5.197M13 7a4 4 0 11-8 0 4 4 0 018 0z" />
  219. </svg>
  220. </span>
  221. </div>
  222. <div class="mt-8">
  223. <h3 class="text-lg font-medium">
  224. <NuxtLink to="/snippets/sol" class="focus:outline-none">
  225. <!-- Extend touch target to entire panel -->
  226. <span class="absolute inset-0" aria-hidden="true"></span>
  227. Solidity Code Snippets
  228. </NuxtLink>
  229. </h3>
  230. <p class="mt-2 text-sm text-gray-500">
  231. Doloribus dolores nostrum quia qui natus officia quod et dolorem. Sit repellendus qui ut at blanditiis et quo et molestiae.
  232. </p>
  233. </div>
  234. <span class="pointer-events-none absolute top-6 right-6 text-gray-300 group-hover:text-gray-400" aria-hidden="true">
  235. <svg class="h-6 w-6" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 24 24">
  236. <path
  237. d="M20 4h1a1 1 0 00-1-1v1zm-1 12a1 1 0 102 0h-2zM8 3a1 1 0 000 2V3zM3.293 19.293a1 1 0 101.414 1.414l-1.414-1.414zM19 4v12h2V4h-2zm1-1H8v2h12V3zm-.707.293l-16 16 1.414 1.414 16-16-1.414-1.414z"
  238. />
  239. </svg>
  240. </span>
  241. </div>
  242. <div class="relative group bg-white p-6 focus-within:ring-2 focus-within:ring-inset focus-within:ring-cyan-500">
  243. <div>
  244. <span class="rounded-lg inline-flex p-3 bg-yellow-50 text-yellow-700 ring-4 ring-white">
  245. <!-- Heroicon name: outline/cash -->
  246. <svg class="h-6 w-6" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" aria-hidden="true">
  247. <path
  248. stroke-linecap="round"
  249. stroke-linejoin="round"
  250. stroke-width="2"
  251. d="M17 9V7a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2m2 4h10a2 2 0 002-2v-6a2 2 0 00-2-2H9a2 2 0 00-2 2v6a2 2 0 002 2zm7-5a2 2 0 11-4 0 2 2 0 014 0z"
  252. />
  253. </svg>
  254. </span>
  255. </div>
  256. <div class="mt-8">
  257. <h3 class="text-lg font-medium">
  258. <NuxtLink to="/smartbch/exchange" class="focus:outline-none">
  259. <!-- Extend touch target to entire panel -->
  260. <span class="absolute inset-0" aria-hidden="true"></span>
  261. Exchange
  262. </NuxtLink>
  263. </h3>
  264. <p class="mt-2 text-sm text-gray-500">
  265. Doloribus dolores nostrum quia qui natus officia quod et dolorem. Sit repellendus qui ut at blanditiis et quo et molestiae.
  266. </p>
  267. </div>
  268. <span class="pointer-events-none absolute top-6 right-6 text-gray-300 group-hover:text-gray-400" aria-hidden="true">
  269. <svg class="h-6 w-6" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 24 24">
  270. <path
  271. d="M20 4h1a1 1 0 00-1-1v1zm-1 12a1 1 0 102 0h-2zM8 3a1 1 0 000 2V3zM3.293 19.293a1 1 0 101.414 1.414l-1.414-1.414zM19 4v12h2V4h-2zm1-1H8v2h12V3zm-.707.293l-16 16 1.414 1.414 16-16-1.414-1.414z"
  272. />
  273. </svg>
  274. </span>
  275. </div>
  276. <div class="sm:rounded-bl-lg relative group bg-white p-6 focus-within:ring-2 focus-within:ring-inset focus-within:ring-cyan-500">
  277. <div>
  278. <span class="rounded-lg inline-flex p-3 bg-rose-50 text-rose-700 ring-4 ring-white">
  279. <!-- Heroicon name: outline/receipt-refund -->
  280. <svg class="h-6 w-6" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" aria-hidden="true">
  281. <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 15v-1a4 4 0 00-4-4H8m0 0l3 3m-3-3l3-3m9 14V5a2 2 0 00-2-2H6a2 2 0 00-2 2v16l4-2 4 2 4-2 4 2z" />
  282. </svg>
  283. </span>
  284. </div>
  285. <div class="mt-8">
  286. <h3 class="text-lg font-medium">
  287. <NuxtLink to="/smartbch/verify" class="focus:outline-none">
  288. <!-- Extend touch target to entire panel -->
  289. <span class="absolute inset-0" aria-hidden="true"></span>
  290. Contract Verification
  291. </NuxtLink>
  292. </h3>
  293. <p class="mt-2 text-sm text-gray-500">
  294. Quickly and easily verify your smart contracts are deployed with the proper bytecode.
  295. </p>
  296. </div>
  297. <span class="pointer-events-none absolute top-6 right-6 text-gray-300 group-hover:text-gray-400" aria-hidden="true">
  298. <svg class="h-6 w-6" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 24 24">
  299. <path
  300. d="M20 4h1a1 1 0 00-1-1v1zm-1 12a1 1 0 102 0h-2zM8 3a1 1 0 000 2V3zM3.293 19.293a1 1 0 101.414 1.414l-1.414-1.414zM19 4v12h2V4h-2zm1-1H8v2h12V3zm-.707.293l-16 16 1.414 1.414 16-16-1.414-1.414z"
  301. />
  302. </svg>
  303. </span>
  304. </div>
  305. <div class="rounded-bl-lg rounded-br-lg sm:rounded-bl-none relative group bg-white p-6 focus-within:ring-2 focus-within:ring-inset focus-within:ring-cyan-500">
  306. <div>
  307. <span class="rounded-lg inline-flex p-3 bg-indigo-50 text-indigo-700 ring-4 ring-white">
  308. <!-- Heroicon name: outline/academic-cap -->
  309. <svg class="h-6 w-6" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" aria-hidden="true">
  310. <path d="M12 14l9-5-9-5-9 5 9 5z" />
  311. <path d="M12 14l6.16-3.422a12.083 12.083 0 01.665 6.479A11.952 11.952 0 0012 20.055a11.952 11.952 0 00-6.824-2.998 12.078 12.078 0 01.665-6.479L12 14z" />
  312. <path
  313. stroke-linecap="round"
  314. stroke-linejoin="round"
  315. stroke-width="2"
  316. d="M12 14l9-5-9-5-9 5 9 5zm0 0l6.16-3.422a12.083 12.083 0 01.665 6.479A11.952 11.952 0 0012 20.055a11.952 11.952 0 00-6.824-2.998 12.078 12.078 0 01.665-6.479L12 14zm-4 6v-7.5l4-2.222"
  317. />
  318. </svg>
  319. </span>
  320. </div>
  321. <div class="mt-8">
  322. <h3 class="text-lg font-medium">
  323. <a href="javascript://" class="focus:outline-none">
  324. <!-- Extend touch target to entire panel -->
  325. <span class="absolute inset-0" aria-hidden="true"></span>
  326. Hire A Developer
  327. </a>
  328. </h3>
  329. <p class="mt-2 text-sm text-gray-500">
  330. Doloribus dolores nostrum quia qui natus officia quod et dolorem. Sit repellendus qui ut at blanditiis et quo et molestiae.
  331. </p>
  332. </div>
  333. <span class="pointer-events-none absolute top-6 right-6 text-gray-300 group-hover:text-gray-400" aria-hidden="true">
  334. <svg class="h-6 w-6" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 24 24">
  335. <path
  336. d="M20 4h1a1 1 0 00-1-1v1zm-1 12a1 1 0 102 0h-2zM8 3a1 1 0 000 2V3zM3.293 19.293a1 1 0 101.414 1.414l-1.414-1.414zM19 4v12h2V4h-2zm1-1H8v2h12V3zm-.707.293l-16 16 1.414 1.414 16-16-1.414-1.414z"
  337. />
  338. </svg>
  339. </span>
  340. </div>
  341. </div>
  342. </section>
  343. </div>
  344. <!-- Right column -->
  345. <div class="grid grid-cols-1 gap-4">
  346. <Blocks :blockHeight="blockHeight" />
  347. <Txs />
  348. </div>
  349. </div>
  350. </div>
  351. </main>
  352. </template>
  353. <script lang="ts">
  354. /* Import components. */
  355. import Blocks from './Blocks'
  356. import Txs from './Txs'
  357. export default {
  358. components: {
  359. Blocks,
  360. Txs,
  361. },
  362. head: () => ({
  363. title: 'Nexa — APECS Dev',
  364. meta: [
  365. {
  366. hid: 'description', // `vmid` for it as it will not work
  367. name: 'description',
  368. content: `Nexa`
  369. }
  370. ]
  371. }),
  372. computed: {
  373. displayBlockHeight() {
  374. if (!this.blockHeight) {
  375. return 0
  376. }
  377. return numeral(Number(this.blockHeight)).format('0,0')
  378. }
  379. },
  380. methods: {
  381. async init() {
  382. setInterval(() => {
  383. this.refresh()
  384. }, 1000)
  385. },
  386. async testMetaMask() {
  387. console.log('STARTING METAMASK TEST..')
  388. /* Validate embedded Web3 objects. */
  389. if (!window.ethereum && !window.bitcoin) {
  390. /* Validate embedded ethereum object. */
  391. if (window.bitcoin) {
  392. console.info('Found Bitcoin provider.')
  393. } else if (window.ethereum) {
  394. console.info('Found Ethereum provider.')
  395. } else {
  396. return console.error('No Web3 provider found.')
  397. }
  398. }
  399. /* Initialize provider. */
  400. const provider = new ethers
  401. .providers
  402. .Web3Provider(window.ethereum, 'any')
  403. /* Prompt user for account connections. */
  404. await provider
  405. .send('eth_requestAccounts', [])
  406. .catch(err => console.error(err))
  407. // await provider.send('wallet_watchAsset', {
  408. // type: 'ERC20',
  409. // options: {
  410. // address: '0x0',
  411. // symbol: 'NAME',
  412. // decimals: 18,
  413. // image: 'https://url.here',
  414. // },
  415. // })
  416. // .catch(err => console.error(err))
  417. /* Set signer. */
  418. const signer = provider.getSigner()
  419. /* Request account. */
  420. this.account = await signer.getAddress()
  421. console.log('Account:', this.account)
  422. // const encryptedMessage = '0x94dac27aa0a733b6561bcf39ca05299595f3eba5f47c93b733c0b4f4674d022f3de31d024c0d427cac86465a565929f340cde5693547ad560000845787ba86be1b'
  423. const encryptedMessage = '0x8996f12a91473c48f0c1df0534d7319def26f0fe756428ec2af08794125477ba6703242c211d858241c47a3c7ba1925dbb2baf9fdb42c71f08cd738139a86f211b'
  424. const msg = await provider
  425. .send('eth_decrypt', [ encryptedMessage, this.account ])
  426. .catch(err => console.error(err))
  427. console.log('DECRYPTED MESSAGE', msg)
  428. // const encryptionKey = await provider
  429. // .send('eth_getEncryptionPublicKey', [ this.account ])
  430. // .catch(err => console.error(err))
  431. // console.log('ENCRYPTION KEY', encryptionKey)
  432. },
  433. async testSigning() {
  434. console.log('STARTING SIGNING TEST..')
  435. /* Validate embedded Web3 objects. */
  436. if (!window.ethereum && !window.bitcoin) {
  437. /* Validate embedded ethereum object. */
  438. if (window.bitcoin) {
  439. console.info('Found Bitcoin provider.')
  440. } else if (window.ethereum) {
  441. console.info('Found Ethereum provider.')
  442. } else {
  443. return console.error('No Web3 provider found.')
  444. }
  445. }
  446. /* Initialize provider. */
  447. const provider = new ethers
  448. .providers
  449. .Web3Provider(window.ethereum, 'any')
  450. /* Set signer. */
  451. const signer = provider.getSigner()
  452. /* Request account. */
  453. this.account = await signer.getAddress()
  454. console.log('Account:', this.account)
  455. // All properties on a domain are optional
  456. // const domain = {
  457. // name: 'APECS',
  458. // version: '1',
  459. // chainId: 0x2711,
  460. // // verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC'
  461. // }
  462. // The named list of all type definitions
  463. // const types = {
  464. // Person: [
  465. // { name: 'name', type: 'string' },
  466. // { name: 'wallet', type: 'address' }
  467. // ],
  468. // Mail: [
  469. // { name: 'from', type: 'Person' },
  470. // { name: 'to', type: 'Person' },
  471. // { name: 'contents', type: 'string' }
  472. // ],
  473. // }
  474. // The data to sign
  475. // const value = {
  476. // from: {
  477. // name: 'Cow',
  478. // wallet: '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826'
  479. // },
  480. // to: {
  481. // name: 'Bob',
  482. // wallet: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB'
  483. // },
  484. // contents: 'Hello, Bob!'
  485. // }
  486. // const signature = await signer
  487. // ._signTypedData(domain, types, value)
  488. // .catch(err => console.error(err))
  489. // console.log('SIGNATURE', signature)
  490. const plaintext = 'hi there everyone!'
  491. const signature = await signer
  492. .signMessage(plaintext)
  493. .catch(err => console.error(err))
  494. console.log('SIGNATURE', signature)
  495. },
  496. smartBCHProvider: function () {
  497. return {
  498. chainId: "0x2710",
  499. rpcUrls: [
  500. "https://smartbch.greyh.at",
  501. "https://smartbch.fountainhead.cash/mainnet",
  502. ],
  503. chainName: "smartBCH",
  504. nativeCurrency: {
  505. name: "Bitcoin Cash",
  506. symbol: "BCH",
  507. decimals: 18,
  508. },
  509. blockExplorerUrls: ["https://smartscan.cash"],
  510. iconUrls: ["https://smartmask.cash/img/smartbch_logo.png"],
  511. }
  512. },
  513. attemptMetaMaskProviderRegistration: async function () {
  514. try {
  515. await window.ethereum.request({
  516. method: "wallet_switchEthereumChain",
  517. params: [{ chainId: "0x2710" }],
  518. })
  519. return true
  520. } catch (switchError) {
  521. // This error code indicates that the chain has not been added to MetaMask.
  522. if (switchError.code === 4902) {
  523. try {
  524. await window.ethereum.request({
  525. method: "wallet_addEthereumChain",
  526. params: [this.smartBCHProvider()],
  527. });
  528. return true;
  529. } catch (addError) {
  530. return false;
  531. }
  532. }
  533. return false
  534. }
  535. },
  536. async refresh() {
  537. //
  538. },
  539. },
  540. created: async function () {
  541. /* Initialize block height. */
  542. // NOTE: Use hex format.
  543. // this.blockHeight = '0x0'
  544. /* Initialize (connected) account. */
  545. // this.account = 'no account connected'
  546. /* Start initialization. */
  547. // this.init()
  548. // this.debugCode = '// place debugging code here'
  549. // this.debugCode = Bitcore.Opcode.OP_EQUALVERIFY
  550. // console.log('HDPrivateKey', HDPrivateKey)
  551. },
  552. mounted: function () {
  553. //
  554. },
  555. }
  556. </script>