Hey Gm folks -
I am n00b in smart contracts so learning as I go - using Nethereum & Infura
I want to query a smart contract on mainnet to get totalsupply
A colleague sent an example using ethers… just trying to move it over - which channel is best to ask?
Example (without contract address and my infuracode) is:
const network = “mainnet”;
const provider = new ethers.providers.InfuraProvider(network, { infura: ‘INFURACODE’ });
const contractAddress = “SMARTCONTRACTADDRESS”;
const contractABI = [{“inputs”: [], “name”: “totalSupply”, “outputs”: [ { “internalType”: “uint256”, “name”: “”, “type”: “uint256” } ],“stateMutability”: “view”,“type”: “function” }];
const contract = new ethers.Contract(contractAddress, contractABI, provider);
async function getSupply(result) {
var supply = await contract.totalSupply();
document.write(’{“supply”:"’+supply+’"}’);
}
getSupply();
Hey Traian, ya I had a look today - just trying to work my way through it
I tried some code using samples etc.
Tried to put it together using ABI provided by my colleague -
I am getting an error: The given key ‘constant’ was not present in the dictionary.
This is at the point that I call var contract = web3.Eth.GetContract(contractABI, contractaddress);
This is the code so far
var web3 = new Web3(TimeSpan.FromSeconds(1), "https://mainnet.infura.io/v3/" + infurakey, null);
var contractABI = @"[{""inputs"": [], ""name"": ""totalSupply"", ""outputs"": [ { ""internalType"": ""uint256"", ""name"": """", ""type"": ""uint256"" } ],""stateMutability"": ""view"",""type"": ""function"" }]";
var contract = web3.Eth.GetContract(contractABI, contractaddress);
var totalSupplyFunction = contract.GetFunction("totalSupply");
var totalSupply = await totalSupplyFunction.CallAsync<BigInteger>(contractaddress);
return totalSupply;
Any ideas ? I thought it might be an issue with ABI but it was working in his ethers.js version