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.
Best Answer
I found this solution working. I didnt change any line of code apart from the below
Previous
Changed:
I have no clue about the reasons.