i am newbie in Python. I am deciphering some lines of code using the Web3.py package and I came across some lines that do not have said package or do not locate it on the web page. I interpret that it is to finally buy the token in question.
Does anyone know which package contract.functions.swapExactETHforTokens belongs to or if it has any binding of the properties?
I tried to look for web3.py and i could not get any information. Someone told me that is a contract function in pancakeswap contract (0x10ED43C718714eb63d5aA57B78B54704E256024E) but i could not find any sintaxis or literature about other codes to use.
I'll be thankfull if you provide me any link to read all properties or how to interpret this parameters linked to Pancakeswap code contract.
I used these links trying to look for an answer:
contract = web3.eth.contract(address=panRouterContractAddress, abi=panabi)
nonce = web3.eth.get_transaction_count(sender_address)
start = time.time()
pancakeswap2_txn = contract.functions.swapExactETHForTokens(
10000000000, # set to 0, or specify minimum amount of tokeny you want to receive - consider decimals!!!
[spend,tokenToBuy],
sender_address,
(int(time.time()) + 10000)
).buildTransaction({
'from': sender_address,
'value': web3.toWei(0.001,'ether'),#This is the Token(BNB) amount you want to Swap from
'gas': 250000,
'gasPrice': web3.toWei('5','gwei'),
'nonce': nonce,
})
This is part of the code i found on Pancakeswap Contract Source Code related to that but i don't know is they are similar to use.
function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
external
virtual
override
payable
ensure(deadline)
returns (uint[] memory amounts)
{
require(path[0] == WETH, 'PancakeRouter: INVALID_PATH');
amounts = PancakeLibrary.getAmountsOut(factory, msg.value, path);
require(amounts[amounts.length - 1] >= amountOutMin, 'PancakeRouter: INSUFFICIENT_OUTPUT_AMOUNT');
IWETH(WETH).deposit{value: amounts[0]}();
assert(IWETH(WETH).transfer(PancakeLibrary.pairFor(factory, path[0], path[1]), amounts[0]));
_swap(amounts, path, to);
}