I'm writing Django app and want to send out tokens using Web3 once Coinpayments sends me callback about successfull payment. The problem is that Coinpayments sends multiple callbacks at once and just in one case tokens are sending, other callbacks get replacement transaction underpriced error. I've already tried to use solutions like add +1 to nonce or remove this parameter, but that doesn't help me because transactions are still building with the same nonce. How can that be fixed or what am I doing wrong?

class CoinpaymentsIPNPaymentView(BaseCoinpaymentsIPNView):
    def post(self, request, order_id, *args, **kwargs):
        status = int(request.POST.get('status'))
        order = Order.objects.get(id=order_id)
        order.status = request.POST.get("status_text")
        if not status >= 100:
            return JsonResponse({"status": status})
        amount = Decimal(request.POST.get('amount1'))
        record = Record.objects.create(
        order.record = record

        gold_record = GoldRecord.objects.get(from_record=record)

        contract = w3.eth.contract(address=CONTRACT_ADDRESS, abi=ABI_JSON)
        transaction = contract.functions.transfer(order.user.wallet.address, int(gold_record.amount * 10 ** 18)).buildTransaction({
            'chainId': 1,
            'gas': 70000,
            'nonce': w3.eth.getTransactionCount(WALLET_ADDRESS)                      # address where all tokens are stored
        signed_tx = w3.eth.account.signTransaction(transaction, WALLET_PRIVATE_KEY)  # signing with wallet's above private key
        tx_hash = w3.eth.sendRawTransaction(signed_tx.rawTransaction)
        tx_receipt = w3.eth.waitForTransactionReceipt(tx_hash)

        return JsonResponse({"status": status})


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.