I have my smart contract deployed on BSC Testnet:
https://testnet.bscscan.com/address/0x01AbBD3c43d447dA73CDee8d138697Df36f785d2
If I connect my Metamask on bscscan, I can use all the write contract methods, however, when I try to invoke methods using Python, I run into the problem of getting error: {'code': -32000, 'message': 'invalid sender'}, when sending the transaction. Here is my code sample:
import json
from web3 import Web3
from web3.middleware import geth_poa_middleware
web3 = Web3(Web3.HTTPProvider('https://data-seed-prebsc-1-s1.binance.org:8545/'))
web3.middleware_onion.inject(geth_poa_middleware, layer=0)
account_from = {
'private_key': 'My Private key',
'address': '0x21Ba7305d6322cD215378D487FfB9C83C42dB82F',
}
contract_address = '0x01AbBD3c43d447dA73CDee8d138697Df36f785d2'
f = open('abi.json',)
abi_file = json.load(f)
abi = abi_file['abi']
contract = web3.eth.contract(address=contract_address, abi=abi)
mint_tx = contract.functions.mintOneNft(Web3.toChecksumAddress('0x46165Fb8A31ab3098BD730876546107271Ced745')).buildTransaction(
{
'from': account_from['address'],
'nonce': web3.eth.get_transaction_count(account_from['address']),
}
)
tx_create = web3.eth.account.sign_transaction(mint_tx, account_from['private_key'])
tx_hash = web3.eth.send_raw_transaction(tx_create.rawTransaction)
Cannot figure out what the problem is here, everything seems pretty straight forward. Help with how to fix it would be much appreciated!