ユーザ用ツール

サイト用ツール


blockchain:静的htmlからipfsにファイルをアップロードする

差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

次のリビジョン
前のリビジョン
blockchain:静的htmlからipfsにファイルをアップロードする [2022/06/14 05:30] – 作成 dotblockchain:静的htmlからipfsにファイルをアップロードする [2022/06/14 06:25] (現在) dot
行 12: 行 12:
  
 <code html> <code html>
-require("@nomiclabs/hardhat-waffle"); 
  
-// This is a sample Hardhat task. To learn how to create your own go to +<html>
-// https://hardhat.org/guides/create-task.html +
-task("accounts", "Prints the list of accounts", async (taskArgs, hre) =+
-  const accounts = await hre.ethers.getSigners();+
  
-  for (const account of accounts) { +<head> 
-    console.log(account.address)+<meta http-equiv="Content-Type" content="text/htmlcharset=UTF-8"> 
-  } +<title>IPFS Uploader</title> 
-});+</head> 
 +<body>
  
-// You need to export an object to set up your config +<script src="https://cdnjs.cloudflare.com/ajax/libs/ipfs/0.63.3-70e142ac.0/index.min.js"></script>
-// Go to https://hardhat.org/configto learn more+
  
-// Go to https://www.alchemyapi.io, sign up, create +<script type="text/javascript" language="javascript"> 
-// a new App in its dashboard, and replace "KEY" with its key +    async function fileSelected(element){ 
-const ALCHEMY_API_KEY = "m4NR445U7JhjZ5gYddoeaQ15KFaiTslL";+        const fileList = element.files; 
 +        const targetFile = fileList[0]; 
 +        const ipfs = await window.Ipfs.create(); 
 +        const _result = await ipfs.add(targetFile); 
 +        let resultElement = document.getElementById("result"); 
 +        resultElement.innerHTML = '<div><p><a href="ipfs://' + _result.path + '" target="_blank">open</a></p><p><a href="https://ipfs.io/ipfs/' + _result.path + 'target="_blank">open ipfs.io public gateway</a></p></div>'; 
 +    } 
 +</script>
  
-// Replace this private key with your Goerli account private key +    <div> 
-// To export your private key from Metamask, open Metamask and +        <input type="file" onChange="fileSelected(this)"/> 
-// go to Account Details Export Private Key +        <div id="result"></div> 
-// Be aware of NEVER putting real Ether into testing accounts +    </div>
-const GOERLI_PRIVATE_KEY = "4f350473ad3e2ae66dd8d9afc545b64c7ab1cff5fb610bbe6e2ab95189d62c05";+
  
-/** +</body> 
- * @type import('hardhat/config').HardhatUserConfig +</html>
- */ +
-module.exports = { +
-  solidity: "0.8.4", +
-  networks: { +
-    hardhat: {}, +
-    goerli: { +
-      url: `https://eth-goerli.alchemyapi.io/v2/${ALCHEMY_API_KEY}`, +
-      accounts: [`${GOERLI_PRIVATE_KEY}`] +
-    } +
-  } +
-};+
 </code> </code>
blockchain/静的htmlからipfsにファイルをアップロードする.1655184620.txt.gz · 最終更新: 2022/06/14 05:30 by dot