Sell fail in BSC chain #72
Replies: 4 comments
-
Hi @rakibmia7254 ! There is at least one error in how you build the Also, just in case:
|
Beta Was this translation helpful? Give feedback.
-
sure about nonce and the token i am trying to sell just bought from there, actually i am trying this on pancakeswap def Approve(self):
permit2_allowance = 2**256 - 1 # max
contract_function = self.w3.eth.contract(address=self.token_address, abi=self.erc20abi).functions.approve(
self.permit2_address,
permit2_allowance
)
trx_params = contract_function.build_transaction(
{
"from": self.account.address,
"gas": 200000,
"maxPriorityFeePerGas": self.w3.eth.max_priority_fee,
"maxFeePerGas": 10 * 10**9,
"type": '0x2',
"chainId": self.chain_id,
"value": 0,
"nonce": self.w3.eth.get_transaction_count(self.account.address),
}
)
raw_transaction = self.w3.eth.account.sign_transaction(trx_params, self.account.key).rawTransaction
trx_hash = self.w3.eth.send_raw_transaction(raw_transaction)
# wait for the transaction to be mined
self.w3.eth.wait_for_transaction_receipt(trx_hash)
# check allowance
p2_amount, p2_expiration, p2_nonce = self.codec.fetch_permit2_allowance(
self.account.address,
self.token_address,
self.router,
permit2=self.permit2_address
)
# permit_data and signable_message
allowance_amount = 2**160 - 1 # max/infinite
permit_data, signable_message = self.codec.create_permit2_signable_message(
self.token_address,
allowance_amount,
self.codec.get_default_expiration(), # 30 days
p2_nonce,
self.router,
self.codec.get_default_deadline(), # 180 seconds
self.chain_id,
verifying_contract=self.permit2_address
)
signed_message = self.account.sign_message(signable_message)
return permit_data, signed_message
def execute(self):
if not self.CheckAllowance():
permit_data, signed_message = self.Approve()
encoded_input = (
self.codec
.encode
.chain()
.permit2_permit(permit_data, signed_message)
.v3_swap_exact_in(FunctionRecipient.SENDER, self.amount_out, self.min_amount_in, self.path, payer_is_sender=False)
.build(self.codec.get_default_deadline())
)
else:
encoded_input = (
self.codec
.encode
.chain()
.v3_swap_exact_in(FunctionRecipient.SENDER, self.amount_out, self.min_amount_in, self.path, payer_is_sender=False)
.build(self.codec.get_default_deadline())
)
trx_params = {
"from": self.account.address,
"to": self.router,
"gas": 200000,
"maxPriorityFeePerGas": self.w3.eth.max_priority_fee,
"maxFeePerGas": 10 * 10**9,
"type": '0x2',
"chainId": self.chain_id,
"value": 0,
"nonce": self.w3.eth.get_transaction_count(self.account.address)+1,
"data": encoded_input,
}
raw_transaction = self.w3.eth.account.sign_transaction(trx_params, self.account.key).rawTransaction
trx_hash = self.w3.eth.send_raw_transaction(raw_transaction)
# wait for the transaction to be mined
self.w3.eth.wait_for_transaction_receipt(trx_hash)
return trx_hash.hex() is there any problem in my code? |
Beta Was this translation helpful? Give feedback.
-
Well, apart from the nonce that I'm still not sure how it could work (but it's unlikely the reason of this failure), I don't see anything else obvious ... On a side note, with the latest lib version (v1.2), you can build directly the full transaction, not just the input data. See doc here Also, have you tried to sell a standard/well known token like WBNB ? |
Beta Was this translation helpful? Give feedback.
-
Moving to discussions as "issues" are for issues in the library itself (or new features). Will move it back if it turns out it's actually one. |
Beta Was this translation helpful? Give feedback.
-
i tried to sell tokens in bsc chain but its just failed
https://bscscan.com/tx/0xd485d57204d9d2a869598be225cedbebb92a2cab1cb27dfffb485eb01d9fcfbd
Beta Was this translation helpful? Give feedback.
All reactions