Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Ionic 6でWeb3やってみた

Avatar for scrpgil scrpgil
May 29, 2022
220

Ionic 6でWeb3やってみた

Avatar for scrpgil

scrpgil

May 29, 2022
Tweet

Transcript

  1. Ionic 6で Web3.0やってみた 大体いい感じのスライドを作るための無料テンプレート VERSION 3.0 CREATED AND MAINTAINED BY

    @SANOGRAPHIX ※このページは削除して構いません USE TEMPLATE Click Ionic Meetup #19 Tokyo LT用資料
  2. MetaMaskとの接続 const connectWallet = () => { window.ethereum .request({ method:

    "eth_requestAccounts" }) .then((result: any) => { console.log(result[0]); setAccount(result[0]); }) .catch((error: any) => { setErrorMessage(error.message); }); }; // window.ethereumはMetaMaskのchrome拡張を入れてると使えるようになる
  3. スマートコントラクト(NFT)の呼び出し 1 const defaultAddress = "0x70fc6b119f24fa14d517C86d334EBaE27E654121"; async function getContractABI(address: any)

    { if (!abi && !abiPending) { setABIPending(true); setABI(defaultAbi); } else if (abi && web3js) { setABIPending(false); const contract = new web3js.eth.Contract(abi, address); const tokenUri = await contract.methods.tokenURI("1").call(); const res: any = await api.get(tokenUri); console.log(res); } } getContractABI(defaultAddress); // defaultAddressはスマコンのアドレス。事前に書き込みが必要。
  4. スマートコントラクト(NFT)の呼び出し 2 // スマコンの返却結果は、metaデータのURL:https://aa-storage.aahub.org/nft/2.json // metaデータを読み出すと以下のJSONが返ってくる { "description": "The most

    famous ASCII art(S-JIS Art)", "external_url": "https://openseacreatures.io/3", "image": "https://aa-storage.aahub.org/aa/7465ba9e8275eb7d34d49c35997b1aa8.png", "name": "オマエモナー", "attributes": [] }
  5. • 複数NFTを読み出すためには、アカウントのトランザクションを全部読み 出す必要あり。 ◦ openseaのAPIを使えば簡単に行える ▪ https://testnets-api.opensea.io/api/v1/assets?owner=${address} ▪ Web3.jsいらないのでは... •

    Web3.jsを使えば、mint(NFTの登録)も行える ◦ 時間がなかったので、今回はhardhatを使って実施。 ▪ https://github.com/scrpgil/sample-hardhat できなかったこと
  6. • 工数比率 ◦ ブロックチェーン周り9割 ◦ Ionic1割 • ただ、1割の工数でそれなりのUI作れるので、やっぱりIonicって良いです ね。 •

    ブロックチェーン界隈、インフラレイヤー感はまだあるので、使いやすいク ライアントアプリを色々出せると良さそう。 Ionic要素少ない