From 6f5fe26013ef0dce73c2483d164a6f962bc27ec5 Mon Sep 17 00:00:00 2001 From: zzy <> Date: Mon, 6 Jun 2022 16:46:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config/abi/erc20.json | 855 +++++++++++++++++++++++++++------- src/config/constants/index.ts | 4 +- src/pages/eth/index.tsx | 123 +++++ 3 files changed, 803 insertions(+), 179 deletions(-) diff --git a/src/config/abi/erc20.json b/src/config/abi/erc20.json index 405d6b3..75474cb 100644 --- a/src/config/abi/erc20.json +++ b/src/config/abi/erc20.json @@ -1,196 +1,28 @@ [ { - "constant": true, "inputs": [], - "name": "name", - "outputs": [ - { - "name": "", - "type": "string" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "_spender", - "type": "address" - }, - { - "name": "_value", - "type": "uint256" - } - ], - "name": "approve", - "outputs": [ - { - "name": "", - "type": "bool" - } - ], - "payable": false, "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "totalSupply", - "outputs": [ - { - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "_from", - "type": "address" - }, - { - "name": "_to", - "type": "address" - }, - { - "name": "_value", - "type": "uint256" - } - ], - "name": "transferFrom", - "outputs": [ - { - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "decimals", - "outputs": [ - { - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "name": "_owner", - "type": "address" - } - ], - "name": "balanceOf", - "outputs": [ - { - "name": "balance", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "symbol", - "outputs": [ - { - "name": "", - "type": "string" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "_to", - "type": "address" - }, - { - "name": "_value", - "type": "uint256" - } - ], - "name": "transfer", - "outputs": [ - { - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "name": "_owner", - "type": "address" - }, - { - "name": "_spender", - "type": "address" - } - ], - "name": "allowance", - "outputs": [ - { - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "payable": true, - "stateMutability": "payable", - "type": "fallback" + "type": "constructor" }, { "anonymous": false, "inputs": [ { "indexed": true, + "internalType": "address", "name": "owner", "type": "address" }, { "indexed": true, - "name": "spender", + "internalType": "address", + "name": "approved", "type": "address" }, { - "indexed": false, - "name": "value", + "indexed": true, + "internalType": "uint256", + "name": "tokenId", "type": "uint256" } ], @@ -202,21 +34,690 @@ "inputs": [ { "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "operator", + "type": "address" + }, + { + "indexed": false, + "internalType": "bool", + "name": "approved", + "type": "bool" + } + ], + "name": "ApprovalForAll", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "minter", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "price", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "nftID", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "string", + "name": "uri", + "type": "string" + } + ], + "name": "Minted", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "nftID", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "bool", + "name": "isListed", + "type": "bool" + } + ], + "name": "NftListStatus", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "previousOwner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "OwnershipTransferred", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "oldPrice", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "newPrice", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "nftID", + "type": "uint256" + } + ], + "name": "PriceUpdate", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "previousOwner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "newOwner", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "price", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "nftID", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "string", + "name": "uri", + "type": "string" + } + ], + "name": "Purchase", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", "name": "from", "type": "address" }, { "indexed": true, + "internalType": "address", "name": "to", "type": "address" }, { - "indexed": false, - "name": "value", + "indexed": true, + "internalType": "uint256", + "name": "tokenId", "type": "uint256" } ], "name": "Transfer", "type": "event" + }, + { + "inputs": [], + "name": "_contractOwner", + "outputs": [ + { + "internalType": "address payable", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "approve", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + } + ], + "name": "balanceOf", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "baseURI", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_id", + "type": "uint256" + } + ], + "name": "buy", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "getApproved", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "internalType": "address", + "name": "operator", + "type": "address" + } + ], + "name": "isApprovedForAll", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "name": "listedMap", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "_tokenURI", + "type": "string" + }, + { + "internalType": "address", + "name": "_toAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "_price", + "type": "uint256" + } + ], + "name": "mint", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "name", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "ownerOf", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "name": "price", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "renounceOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "safeTransferFrom", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + }, + { + "internalType": "bytes", + "name": "_data", + "type": "bytes" + } + ], + "name": "safeTransferFrom", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "operator", + "type": "address" + }, + { + "internalType": "bool", + "name": "approved", + "type": "bool" + } + ], + "name": "setApprovalForAll", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes4", + "name": "interfaceId", + "type": "bytes4" + } + ], + "name": "supportsInterface", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "symbol", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "index", + "type": "uint256" + } + ], + "name": "tokenByIndex", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "internalType": "uint256", + "name": "index", + "type": "uint256" + } + ], + "name": "tokenOfOwnerByIndex", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "tokenURI", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "totalSupply", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "transferFrom", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "transferOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_tokenId", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "shouldBeListed", + "type": "bool" + } + ], + "name": "updateListingStatus", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_tokenId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_price", + "type": "uint256" + } + ], + "name": "updatePrice", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" } ] diff --git a/src/config/constants/index.ts b/src/config/constants/index.ts index 4b80f33..eafecea 100644 --- a/src/config/constants/index.ts +++ b/src/config/constants/index.ts @@ -1,2 +1,2 @@ -export const ACCOUNT = '0x6555e1cc97d3cba6eaddebbcd7ca51d75771e0b8'; -export const ETH_CONTRACT = '0xc011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f'; +export const ACCOUNT = '0xF75037b4b36B8d8ee21D83943A87d540E53760f1'; +export const ETH_CONTRACT = '0x1e58e4289996ed261ecf4d6df22ee0aa1c983c2b'; diff --git a/src/pages/eth/index.tsx b/src/pages/eth/index.tsx index 039006c..d20f1af 100644 --- a/src/pages/eth/index.tsx +++ b/src/pages/eth/index.tsx @@ -4,6 +4,8 @@ import ercAbi from '@/config/abi/erc20.json'; import { ACCOUNT, ETH_CONTRACT } from '@/config/constants'; const IndexPage = () => { + const privateKey = + '2a5bc921f8887bdf3c5a0cb6ad6f65e16e1b0f4d797713439f7cc71e52eb100f'; const web3 = new Web3(Web3.givenProvider); const myContract = new web3.eth.Contract(ercAbi, ETH_CONTRACT); const getBalance = async () => { @@ -11,11 +13,114 @@ const IndexPage = () => { console.log('getBalance', res); }; + // balanceOf + const contractCall = async () => { + const res = await myContract.methods.balanceOf(ACCOUNT).call(); + console.log('contractCall', res); + }; + + const getGasPrice = async () => { + const res = await web3.eth.getGasPrice(); + console.log('gasPrice = ', res); + return res; + }; + + // const get = async () => { + // const res = await myContract.methods.get('nana').call(); + // console.log('contractCall', res); + // }; + + // const add = async () => { + // var functionEncode = await myContract.methods + // .add('nana', 'nnnn') + // .encodeABI(); + // var sign = await web3.eth.accounts.signTransaction( + // { + // gas: 300000, + // to: ETH_CONTRACT, + // data: functionEncode, + // }, + // privateKey, + // ); + // var result = await web3.eth.sendSignedTransaction(sign.rawTransaction); + // console.log('setName txHash = ' + result.transactionHash); + // // console.log('result = ' + result); + // }; + + // const getTopics = async () => { + // var topic = web3.eth.abi.encodeFunctionSignature({ + // inputs: [ + // { + // internalType: 'string', + // name: '_tokenURI', + // type: 'string', + // }, + // { + // internalType: 'address', + // name: '_toAddress', + // type: 'address', + // }, + // { + // internalType: 'uint256', + // name: '_price', + // type: 'uint256', + // }, + // ], + // name: 'mint', + // outputs: [ + // { + // internalType: 'uint256', + // name: '', + // type: 'uint256', + // }, + // ], + // stateMutability: 'nonpayable', + // type: 'function', + // }); + // console.log('topic = ', topic); + // }; + + const getPastEvents = async () => { + var getPastEvents = await myContract.getPastEvents('AllEvents', { + fromBlock: 0, // 起始块 + toBlock: 'latest', // 终止块 + }); + console.log('pastLogs = ', getPastEvents); + }; + + const mint = async () => { + var functionEncode = await myContract.methods + .mint( + 'http://124.223.202.96:18088/6', + '0x75B79CE63b0AAc451FA125F591Ab2a16575d94A8', + 1, + ) + .encodeABI(); + var sign = await web3.eth.accounts.signTransaction( + { + gas: 300000, + to: ETH_CONTRACT, + data: functionEncode, + chainId: 5, + }, + privateKey, + ); + var result = await web3.eth.sendSignedTransaction(sign.rawTransaction); + console.log('setName txHash = ' + result.transactionHash); + // console.log('result = ' + result); + }; + + const name = async () => { const res = await myContract.methods.name().call(); console.log('contractCall', res); }; + const tokenURI = async () => { + const res = await myContract.methods.tokenURI(2).call(); + console.log('contractCall', res); + }; + return (

ETH

@@ -27,6 +132,24 @@ const IndexPage = () => { + + + + + + {/* */}

其他