Closed saarshah closed 4 years ago
Error: insufficient data for uint256 type (arg="", coderType="uint256", value="0x", version=4.0.39)
It look like you called a method which should return a "uint256" but got "0x", and abi-docoder can not handle it and throw insufficient data for uint256 type
.
I checked my contract (see below). I have also called directly getTotalSupply
function , still same error..
code to deploy and immediately called its function
async function deployCon(key) {
abi = sources[key].abi;
code = "0x"+sources[key].bytecode;
const contract = cfx.Contract({ abi, code });
const estimateDeployGas = await contract.constructor(...constructorParameters[key].input).estimateGas();
const contractAddress = await contract.constructor(...constructorParameters[key].input)
.sendTransaction({
from:account,
gas: estimateDeployGas,
})
.deployed();
console.log("Address of Contract: ", contractAddress);
contract.address = contractAddress;
console.log(await contract.getTotalSupply());
return contract;
}
MyContract.sol
pragma solidity ^0.5.12;
contract MyContract {
uint256 public totalSupply ;
mapping( address => uint256) public balances ;
address payable public owner;
constructor(address payable _wallet) public payable {
totalSupply = 6;
owner = _wallet;
}
function () external payable{
buyToken();
}
function buyToken() public payable {
require(totalSupply >= (msg.value/1000000000000000000)*2);
balances[msg.sender] += (msg.value/1000000000000000000)*2;
totalSupply -=(msg.value/1000000000000000000)*2;
}
function getTotalSupply()public view returns (uint256 ){
return totalSupply;
}
function setTotalSupply(uint256 newSupply) public returns (uint256 ) {
totalSupply = newSupply;
return totalSupply;
}
}
I have also tested the code of example, (which you provided earlier).. it also giving same error...
I am trying to deploy contract and then calling its getter and setter functions. I can deployed my contract through program and got its address and then i feed this newly got address to my getter and setter functions, it become error (given below). However, if i just saved that address as hard coded, then my all program works well as expected. Error:
and here is my program
UPDATED: I checked my contract (see below). I haved also called directly
getTotalSupply
function , still same error..code to deploy and immediately called its function
MyContract.sol