I have deployed a simple contract on the BSC testnet which has a simple function that executes a swap on Pancakeswap.
This is how I call the function with Brownie:
def main():
tx = contract1.buyToken(0.01,10000,'0x094616F0BdFB0b526bD735Bf66Eca0Ad254ca81F','0xC880a918eDB02E9cf006369927a68c5e7F778B4B')
return True
And I get this error:
Running '\python_projects\docs3\coin_observer\brownie\scripts\testz.py::main'...
File "c:\users\home\appdata\roaming\python\python38\lib\site-packages\brownie\_cli\run.py", line 50, in main
return_value, frame = run(
File "c:\users\home\appdata\roaming\python\python38\lib\site-packages\brownie\project\scripts.py", line 103, in run
return_value = f_locals[method_name](*args, **kwargs)
File "\python_projects\docs3\coin_observer\brownie\scripts\testz.py", line 7, in main
tx = contract1.buyToken(0.01,10000,'0x094616F0BdFB0b526bD735Bf66Eca0Ad254ca81F','0xC880a918eDB02E9cf006369927a68c5e7F778B4B')
AttributeError: 'ContractContainer' object has no attribute 'buyToken'
And here is the Solidity part:
function buyToken(uint amountToSpend, uint amountToBuy, address tokenToSpendAddress, address tokenToBuyAddress) public returns (uint[] memory amounts) {
require(address(this).balance > amountToSpend);
uint256[] memory receivedTokens;
address[] memory path = new address[](2);
path[0] = tokenToSpendAddress;
path[1] = tokenToBuyAddress;
receivedTokens = _pancakeRouter.swapExactETHForTokens{value: amountToSpend}(amountToBuy,path,address(this),block.timestamp + 30);
return receivedTokens;
}
So my problem is why I get the object has no attribute 'buyToken'
error? The buyToken
exists in the contract and it compiled correctly.
UPDATE
I compiled and deployed the contract again and printed the ABI that seems fine, it contains the function, but the error still exists. I assume something with the ContractContainer
is wrong.