使用 Web3 转币时,gas 费可以从另一个账户支付吗?
Can gas fees be paid from another account when transferring tokens using Web3?
bsc = 'https://bsc-dataseed.binance.org/'
web3 = Web3(Web3.HTTPProvider(bsc))
# print(web3.isConnected())
account_1 = '0xXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
private_key1 = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
account_2 = '0xXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
balance = web3.eth.get_balance(account_1)
human_readable = web3.fromWei(balance, 'ether')
print("Balance : " + str(human_readable))
if balance > 0.01:
nonce = web3.eth.getTransactionCount(account_1)
tx = {
'nonce': nonce,
'to': account_2,
'value': web3.toWei(balance, 'ether'),
'gas': 21000,
'gasPrice': web3.toWei(5, 'gwei')
}
signed_tx = web3.eth.account.sign_transaction(tx, private_key1)
tx_hash = web3.eth.sendRawTransaction(signed_tx.rawTransaction)
print(web3.toHex(tx_hash))
我正在使用此代码进行转帐。但是,在进行这些交易时,我想用另一个账户支付转账费用。可能吗。
签约、批准...
I am transferring with this code. However, while doing these transactions, I want to pay the transfer fee with another account. Is it possible. Contract, approve
You can read about meta transactions and gasless transactions here.
它们未在 BNB Chain 上实现,因此不可能。
bsc = 'https://bsc-dataseed.binance.org/'
web3 = Web3(Web3.HTTPProvider(bsc))
# print(web3.isConnected())
account_1 = '0xXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
private_key1 = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
account_2 = '0xXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
balance = web3.eth.get_balance(account_1)
human_readable = web3.fromWei(balance, 'ether')
print("Balance : " + str(human_readable))
if balance > 0.01:
nonce = web3.eth.getTransactionCount(account_1)
tx = {
'nonce': nonce,
'to': account_2,
'value': web3.toWei(balance, 'ether'),
'gas': 21000,
'gasPrice': web3.toWei(5, 'gwei')
}
signed_tx = web3.eth.account.sign_transaction(tx, private_key1)
tx_hash = web3.eth.sendRawTransaction(signed_tx.rawTransaction)
print(web3.toHex(tx_hash))
我正在使用此代码进行转帐。但是,在进行这些交易时,我想用另一个账户支付转账费用。可能吗。 签约、批准...
I am transferring with this code. However, while doing these transactions, I want to pay the transfer fee with another account. Is it possible. Contract, approve
You can read about meta transactions and gasless transactions here.
它们未在 BNB Chain 上实现,因此不可能。