I have 3 solidity contracts, main.sol, provider.sol and allowance.sol
Now from main.sol, I am calling a function "Transact", which calls another function "Transact" in provider.sol (there's a Transact function in main and one in provider).
I'm using remix ide. Now, from the deploy and run transactions tab, I call the Transact function of main.sol, it throws an error saying:
revert The transaction has been reverted to the initial state. Note: The called function should be payable if you send value and the value you send should be less than your current balance. Debug the transaction to get more information. but when I call the Transact function of provider.sol directly, it runs without any errors! and the transfer of eth goes through!
Any idea why this is happening?
Here are both the transact functions for reference:
From main.sol
function Transact(address _recipientAddress, uint256 _amount, address _behalfAddress) external payable { Receivers memory receiver = receivers[_behalfAddress]; address providerAddress = receiver.ProviderAddress; address allowanceContractAddress = receiver.contractAddress; require(allowanceContractAddress != address(0), "Allowance contract not found"); ProviderContract providerContractInstance = ProviderContract(payable(providerAddress)); AllowanceContract allowanceContractInstance = AllowanceContract(allowanceContractAddress); allowanceContractInstance.Transact(_amount); // Call the Transact function of the ProviderContract to make the payment // THIS IS THE LINE THE ERROR IS COMING IN (FOUND IN DEBUGGING) providerContractInstance.Transact(_recipientAddress, _amount, _behalfAddress); } From Provider.sol:
function Transact(address _recipient, uint _amount, address _benefactorAddress) external payable { string memory behalfName = benefactors[_benefactorAddress]; Transaction memory newTransaction = Transaction({ amount: _amount, recipient: _recipient, timestamp: block.timestamp, behalf: behalfName }); transactions.push(newTransaction); for (uint i = 0; i < allowances.length; i++) { if (allowances[i].walletAddress == _recipient) { allowances[i].allowanceSpent += _amount; break; } } address _recipientaddress = _recipient; bytes memory rand; (bool sent, bytes memory data) = payable(_recipientaddress).call{value: _amount}(""); require(sent, "Failed to send Ether"); rand = data; } Please note that I am not sending any ether as value while calling the functions. I want the provider.sol contract to use it's own balance (Balance in the contract address) and I am making sure that the contract balance is sufficient. (As I mentioned, the functionality is working when I directly call provider.sol's Transact Function)
Transact()function ofMaincontract, provided that theProvidercontract has sufficient ETH balance (i.e., >=_amount). Can you please confirm by trying on your end ?Providercontract whenever a provider is registered.Providercontract, not theMaincontract. And it worked fine.