I create a custom ERC20Token and a contract to store data sent from web3.Js. after storing data in mapping I would like to call ERC20Token contracts functionality inside this contract.
code of contract to store data in mapping.
import './EMPToken.sol';
contract socialposts {
//address payable public owner;
EMPToken token;
address _empTokenAdr = 0xd3591733C103EaCfBE7e0c2b4C037764dA836FDe;
constructor() public {
// owner = msg.sender;
createPost('I am using Blokchain','David Abrahim');
}
function createPost(string memory content,string memory name) public {
postCount++;
posts[postCount] = post(postCount,content,name,msg.sender);
//msg.sender.transfer(msg.value);
token = EMPToken(_empTokenAdr);
token.approve(msg.sender,2);
}
}
Below are the version information Truffle v5.1.5 (core: 5.1.5) Solidity v0.5.12 (solc-js) Node v10.16.3 Web3.js v1.2.1
I am using Ganache blockchain with truffle. "socialposts" is a contract that takes input from UI and stores(I didnt include all code of this contract here). EMPToken.sol is my custom ERC Token. I want to trigger the "transfer" function of ERCToken inside "socialposts" contract.
Below is the error message i am getting
Error: * Deployment Failed *
"socialposts" hit a require or revert statement somewhere in its constructor. Try: * Verifying that your constructor params satisfy all require conditions. * Adding reason strings to your require statements.
postCount
,posts
,post
. Since it doesn't compile, you couldn't possibly get a revert error while deploying it (not compiled ==> no bytecode ==> nothing to deploy)!!!require
orrevert
somewhere", and your comment above says "token.approve(msg.sender,2);
is where the issue is". The simple conclusion is that you've hit arequire
orrevert
inside functionapprove
, whose code is exactly the required info that you haven't added! So please start by looking into this yourself, and if you can't find the reason then post the code of that function in here.