Invalid type for argument in function call. Invalid implicit conversion from contract AstTokenSale to address requested.
I have this error and do not know how to fix it can someone help me
here is the code
require(tokenContract.transfer(admin, tokenContract.balanceOf(this)));
The error stating that Invalid implicit conversion from contract AstTokenSale to address requested meaning that you have to cast to address explicitly.
Try this require(tokenContract.transfer(admin, tokenContract.balanceOf(address(this))));
Related
When I ran a web3 function at Remix, it show me the full error message, then I can easily to debug and fix. But when I called function from my own frontend and Metamask, the error message is not clearly. You can check it here https://imgur.com/a/QS4q0ER ( pic1: remix, pic2: metamask )
By using estimateGas (https://ethereum.stackexchange.com/questions/21654/correct-syntax-for-estimating-gas-cost-of-a-function-in-web3/21765#21765) I can get the error message. But it's not clearly. I tried to decode data field. The result here https://i.imgur.com/8r3eF18.png . I can see the error message here, but not exactly in right format.
Please help me to decode the error message, using this hex string :
0x08c379a000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000017707269636520736c697070616765206465746563746564000000000000000000
Found it.
web3.eth.abi.encodeFunctionSignature('Error(string)') = '0x08c379a0'
Remove 0x08c379a0 in data string, and decode it:
web3.eth.abi.decodeParameter('string', '00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000017707269636520736c697070616765206465746563746564000000000000000000') = 'price slippage detected'
I use Ganache, truffle.
I get the following error:
Error: [ethjs-query] while formatting outputs from RPC '{"value":{"code":-32603,"data":{"message":"VM Exception while processing transaction
I have located the problematic piece of code:
bool sent = _sellerAddress.send(_price);
Now, I get the price via the user interaction, and when the price is 0, then the error is not thrown,
unfortunately in the classic case when the _price is no zero, the exception is thrown.
Any suggestions?
Newbie.
There is a go-ethereum method:
eth.estimateGas({from:'firstAccount', to:'secondAccount'})
that works well,
but same method with contract address like:
eth.estimateGas({from:'firstAccount', to:'contractAddr'})
fails with error
gas required exceeds allowance or always failing transaction
I have looked into go-ethereum source code and it has the line, that contains proposal to use contract address as second parameter:
https://github.com/ethereum/go-ethereum/blob/master/accounts/abi/bind/base.go#L221
The question is: is there any possibily to use eth.estimateGas with contract address as second parameter and how to avoid above error?
Thank you.
You're not specifying what you're executing in the contract, so there's nothing to estimate. When you estimateGas for a transfer to an EOA account, there is no contract code to execute, so there is no message data to be sent as part of the transaction object. If you're estimating gas on a contract call, you need to include the data for the contract.
For example, if you want to estimate gas to setValue(2) method in this contract
pragma solidity ^0.4.19;
contract SimpleContract {
uint256 _value;
function setValue(uint256 value) public {
_value = value;
}
}
your call would be
var data = '552410770000000000000000000000000000000000000000000000000000000000000002';
eth.estimateGas({from: fromAccount, to: contractAddress, data});
The value for data comes from encoding the function signature and the parameter value(s). You can use a simple tool (like https://abi.hashex.org) to generate this. You just enter the function name along with the parameter argument types and their values, and it will generate the message data for you. You can also do this using web3js.
EDIT - I neglected to consider contracts with fallback functions. Executing estimateGas on a contract without passing in message data provide the estimate for contracts that have a fallback function. If the contract does not have a fallback function, the call will fail.
I am getting this exception "Object must implement IConvertible." while converting rules to tolist(). below is my code
var rules = from m in db.Rules select m;
return rules.ToList().ToDataTable(); // exception occurs here
I am using MySQL 6.3.6 ..the same code is working fine with MSSQL.
I will be grateful if someone helps me in this
regards
Umair
Make sure the source type is convertible to the destination type.
Probably the rules.ToList() don't match with you ToDataTable destination cast.
Can you verify what var list = rules.ToList() contains?
And... I suggest deal with List and IEnumerable against Datatable.
I am working on some simple object-oriented code in MATLAB. I am trying to call one of my class methods with no input or output arguments in its definition.
Function definition:
function roll_dice
Function call:
obj.roll_dice;
When this is executed, MATLAB says:
??? Error using ==> roll_dice
Too many input arguments.
Error in ==> DiceSet>Diceset.Diceset at 11
obj.roll_dice;
(etc...)
Anyone have any ideas what could be causing it? Are there secret automatic arguments I'm unaware that I'm passing?
When you make the call:
obj.roll_dice;
It is actually equivalent to:
roll_dice(obj);
So obj is the "secret" automatic argument being passed to roll_dice. If you rewrite the method roll_dice to accept a single input argument (even if you don't use it), things should work correctly.
Alternatively, if you know for sure that your method roll_dice is not going to perform any operations on the class object, you can declare it to be a static method as Dan suggests.
For more information on object-oriented programming in MATLAB, here's a link to the online documentation.
I believe you can also get around this by declaring roll_dice to be a static method.