0

I have an Alchemy project through which I have received transactions. I would like to tokenize these transactions using the following Python script:

import json
from web3 import Web3

# Codes de couleur ANSI
GREEN = '\033[92m'
RESET = '\033[0m'

# Charger la configuration
with open('config.json') as config_file:
    config = json.load(config_file)

alchemy_url = config['alchemy_url']
private_key = config['private_key']
account_address = config['account_address']
wabbc_contract_address = '###############################################'

# Connectez-vous à Alchemy
w3 = Web3(Web3.HTTPProvider(alchemy_url))

# Vérifiez la connexion
if not w3.is_connected():
    print("Échec de la connexion à Alchemy")
    exit()

# Charger l'ABI du contrat
with open('contract_abi.json') as abi_file:
    wabbc_abi = json.load(abi_file)

# Obtenir une instance du contrat
wabbc_contract = w3.eth.contract(address=wabbc_contract_address, abi=wabbc_abi)

# Fonction pour générer les tokens WABBC et sauvegarder les transactions
def generate_wabbc_tokens(block_data):
    transactions = []
    nonce = w3.eth.get_transaction_count(account_address)

    for block in block_data:
        block_number = block['number']
        block_hash = block['hash']
        
        for tx in block['transactions']:
            tx_value = tx['value']
            tx_from = tx['from']
            tx_to = tx['to']

            # Tokeniser uniquement les transactions avec une valeur supérieure à zéro
            if tx_value > 0:
                # Tokeniser la transaction
                tx_hash = tokenise_transaction(tx_value, tx_from, tx_to, nonce)
                print(f'Tokenised transaction {tx["hash"]}: {tx_hash}')

                # Ajouter les détails de la transaction au fichier
                transactions.append({
                    'original_tx_hash': tx['hash'],
                    'new_tx_hash': tx_hash,
                    'from': tx_from,
                    'to': tx_to,
                    'value': tx_value,
                    'block_number': block_number,
                    'block_hash': block_hash,
                })

                # Sauvegarder les transactions générées dans un fichier JSON
                with open('generated_transactions.json', 'w') as f:
                    json.dump(transactions, f, indent=4)

                nonce += 1  # Incrémenter le nonce pour chaque transaction

# Fonction pour tokeniser une transaction
def tokenise_transaction(value, from_address, to_address, nonce):
    # Construire la transaction pour générer des tokens
    txn = wabbc_contract.functions.mint(to_address, value).build_transaction({
        'chainId': 1,  # Assurez-vous que cela correspond à votre réseau
        'gas': 1000000,
        'gasPrice': w3.to_wei('10', 'gwei'),  # Augmenter le prix du gaz
        'nonce': nonce,
    })

    # Signer la transaction
    signed_txn = w3.eth.account.sign_transaction(txn, private_key=private_key)
    
    # Envoyer la transaction
    tx_hash = w3.eth.send_raw_transaction(signed_txn.rawTransaction)
    
    return w3.to_hex(tx_hash)

# Lire les transactions depuis le fichier JSON
with open('blocks.json', 'r') as f:
    block_data = json.load(f)

# Générer les tokens WABBC à partir des transactions et sauvegarder les transactions
generate_wabbc_tokens(block_data)

The script runs fine, I am debited, but I do not receive any tokens. When I check on etherscan.io, I see the following message which I do not understand: "Warning! Error encountered during contract execution [execution reverted]"

4
  • 1
    Is your mint() function having any modifiers like onlyOwner or so? If yes, then are you using the account (to sign the corresponding transaction) that fulfils the conditions of the modifier(s)? Commented Jul 26 at 0:27
  • @James CARTER Show us the transactions hash
    – shadow
    Commented Jul 26 at 1:39
  • @shadow This is the Hash: 0x2e9fed4fd6271c6605f1819ea32ed45ee719dae2ec5ceacc35c83b4e6e3a74e8 Commented Jul 27 at 4:30
  • this is the contract @SYEDASADKAZMI 0xe83cE6bfb580583bd6A62B4Be7b34fC25F02910D Commented Jul 27 at 4:33

1 Answer 1

0

You don't have permission to mint(), only the owner does. The owner is 0xAe4799e0CA4C1AC972932a448D7F3dbB205Baf5B. The address calling the mint() is 0x1E6d2D4B3bf4bf9D82a0E5A18F6688B39D9fE733

  modifier hasMintPermission() {
    require(msg.sender == owner);
    _;
  }

It causes this modifier's require statement to fail.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.