20
loading...
This website collects cookies to deliver better user experience
yarn create react-app read-from-ethereum
yarn add ethers
import { ethers } from “ethers”;
const provider = new ethers.providers.JsonRpcProvider('https://cloudflare-eth.com');
provider.getBlockNumber().then( r => { console.log( r ) } );
A smart contract address, which is generated once a contract is deployed to ethereum and becomes its permanent reference to be called when we need to interact with it;
the contract’s ABI, which is the mapping of what are the functions and their return types that will help our script understand how to communicate with it.
const contractAddress = “0x2A46f2fFD99e19a89476E2f62270e0a35bBf0756”;
const ABI = [{“constant”:true,”inputs”:[],”name”:”currentStartingDigitalMediaId”,”outputs”:[{“name”:””,”type”:”uint256"}],”payable”:false,”stateMutability”:”view”,”type”:”function”},{“constant”:true,”inputs”:[{“name”:”_interfaceID”,”type”:”bytes4"}],”name”:”supportsInterface”,”outputs”:[{“name”:””,”type”:”bool”}],”payable”:false,”stateMutability”:”view”,”type”:”function”},{“constant”:false,”inputs”:[{“name”:”_metadataPath”,”type”:”string”}]…
const contract = new ethers.Contract(contractAddress, ABI, provider);
tokenOwner[_tokenId] = _to;
const NFT = 40913;
contract.ownerOf(NFT).then( r => { console.log( r ) } );
const address_of_the_owner_of_expensive_nft = "0x8bB37fb0F0462bB3FC8995cf17721f8e4a399629";
provider.getBalance(address_of_the_owner_of_expensive_nft).then( r => { console.log( r ) } );
provider.getBalance(address_of_the_owner_of_expensive_nft).then( r => { console.log( ethers.utils.formatEther(r) ) } );