0

Trying to call a function that takes a parameter from my contract on BSC. The parameter is an address. The signing of the transaction goes well but when I get to send_raw_transaction I get hit with "'str' object has no attribute 'request_func'".

Using send_transaction alone gives off this error : "a bytes-like object is required, not 'str'"

import json

from web3.auto import w3
from web3.middleware import geth_poa_middleware
from web3 import Web3

# Set up the connection to the network.
bsc = Web3(Web3.HTTPProvider('https://bsc-dataseed.binance.org/'))
bsc.middleware_onion.inject(geth_poa_middleware, layer=0)
print(bsc.isConnected())

w3 = Web3('https://bsc-dataseed.binance.org/')

            nonce = bsc.eth.get_transaction_count('ADDRESS_ETC')

            hex_string = bytes.fromhex('ADDRESS_ETC')

            privateKey = "PRIVATE_KEY_ETC"
            account = w3.eth.account.privateKeyToAccount(privateKey)

            unicorn_txn = contract.functions.myFunction(
                hex_string
            ).build_transaction({
                'chainId': 56,
                'gas': 70000,
                'maxFeePerGas': w3.toWei('2', 'gwei'),
                'maxPriorityFeePerGas': w3.toWei('1', 'gwei'),
                'nonce': nonce,
                'from': account.address,
            })

            print(unicorn_txn)
            
            signed_txn = w3.eth.account.sign_transaction(unicorn_txn, private_key=privateKey)

            signed_txn.rawTransaction

            signed_txn.r

            signed_txn.s

            signed_txn.v

            w3.eth.send_transaction(signed_txn.rawTransaction)

Expected the transaction to go through, it didn't

1
  • Please edit your question to include the entire error message. Commented Dec 20, 2022 at 20:25

1 Answer 1

1

Where you have

w3 = Web3(url)

you need to have

w3 = Web3(Web3.HTTPProvider(url))

This is a tricky one, as the problem doesn't appear until you try to make certain calls using w3.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.