|
| 1 | +<template lang="html"> |
| 2 | + <div class=""> |
| 3 | + <p>eth page</p> |
| 4 | + </div> |
| 5 | +</template> |
| 6 | + |
| 7 | +<script> |
| 8 | +import { ethers } from 'ethers' |
| 9 | +export default { |
| 10 | +
|
| 11 | + mounted: function () { |
| 12 | +
|
| 13 | + if(process.client){ |
| 14 | +
|
| 15 | + if (typeof window.ethereum !== 'undefined') { |
| 16 | +
|
| 17 | + ethereum.enable() |
| 18 | + .then((accounts) => { |
| 19 | + const provider1 = new ethers.providers.Web3Provider(web3.currentProvider); |
| 20 | +
|
| 21 | + // There is only ever up to one account in MetaMask exposed |
| 22 | + const signer = provider1.getSigner(); |
| 23 | + console.log(signer) |
| 24 | + }) |
| 25 | +
|
| 26 | + } |
| 27 | + } |
| 28 | +
|
| 29 | +
|
| 30 | +
|
| 31 | +
|
| 32 | +
|
| 33 | + let provider = ethers.getDefaultProvider('ropsten'); |
| 34 | + let randomWallet = ethers.Wallet.createRandom(); |
| 35 | + console.log(randomWallet) |
| 36 | +
|
| 37 | + let address = "0x4e669903a85fB3Da7D5eB6000F85E44bD967eA01"; |
| 38 | +
|
| 39 | + provider.getBalance(address).then((balance) => { |
| 40 | +
|
| 41 | + // balance is a BigNumber (in wei); format is as a sting (in ether) |
| 42 | + let etherString = ethers.utils.formatEther(balance); |
| 43 | +
|
| 44 | + console.log("Balance: " + etherString); |
| 45 | + }); |
| 46 | + provider.getTransactionCount(address).then((transactionCount) => { |
| 47 | + console.log("Total Transactions Ever Sent: " + transactionCount); |
| 48 | + }); |
| 49 | +
|
| 50 | +
|
| 51 | +
|
| 52 | + let abi = [ |
| 53 | + "constructor(string symbol,string name,uint8 dec,uint256 supply)", |
| 54 | + "function name() public view returns (string name)", |
| 55 | + "function symbol() public view returns (string symbol)", |
| 56 | + "function decimals() public view returns (uint8 dec)", |
| 57 | + "function totalSupply() public view returns (uint256 supply)" |
| 58 | +]; |
| 59 | +
|
| 60 | +// The bytecode from Solidity, compiling the above source |
| 61 | +let bytecode = "" |
| 62 | +
|
| 63 | +
|
| 64 | +
|
| 65 | +
|
| 66 | +// Load the wallet to deploy the contract with |
| 67 | +let privateKey = '834660FF71673FB513C3954EBEB0B7B466DB8388F4D818CA6C2A77554801DBDF'; |
| 68 | +let wallet = new ethers.Wallet(privateKey, provider); |
| 69 | +
|
| 70 | +// Deployment is asynchronous, so we use an async IIFE |
| 71 | +(async function() { |
| 72 | +
|
| 73 | + // Create an instance of a Contract Factory |
| 74 | + let factory = new ethers.ContractFactory(abi, bytecode, wallet); |
| 75 | +
|
| 76 | +
|
| 77 | +
|
| 78 | + // Notice we pass in "Hello World" as the parameter to the constructor |
| 79 | + let contract = await factory.deploy('bnn','banla',4,30000); |
| 80 | + console.log(contract.interface.functions) |
| 81 | + // The address the Contract WILL have once mined |
| 82 | + // See: https://ropsten.etherscan.io/address/0x2bd9aaa2953f988153c8629926d22a6a5f69b14e |
| 83 | + console.log(contract.address); |
| 84 | + // "0x2bD9aAa2953F988153c8629926D22A6a5F69b14E" |
| 85 | +
|
| 86 | + // The transaction that was sent to the network to deploy the Contract |
| 87 | + // See: https://ropsten.etherscan.io/tx/0x159b76843662a15bd67e482dcfbee55e8e44efad26c5a614245e12a00d4b1a51 |
| 88 | + console.log(contract.deployTransaction); |
| 89 | + // "0x159b76843662a15bd67e482dcfbee55e8e44efad26c5a614245e12a00d4b1a51" |
| 90 | +
|
| 91 | + // The contract is NOT deployed yet; we must wait until it is mined |
| 92 | + await contract.deployed() |
| 93 | +
|
| 94 | +
|
| 95 | +
|
| 96 | +
|
| 97 | + // Done! The contract is deployed. |
| 98 | +})(); |
| 99 | +} |
| 100 | +} |
| 101 | +</script> |
| 102 | + |
| 103 | +<style lang="css" scoped > |
| 104 | +
|
| 105 | +</style> |
0 commit comments