1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| from web3 import Web3
from Constant.Strategy.StrategyConstant import StrategyType
abi = """[{"inputs":[{"internalType":"address","name":"tokenaddress","type":"address"},{"internalType":"address","name":"toaddress","type":"address"},{"internalType":"uint256","name":"tokenAmount","type":"uint256"}],"name":"tokenTransfer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"stateMutability":"nonpayable","type":"constructor"}]"""
class Multiswap: name = StrategyType.MULTISWAP.value
def __init__(self, strategyEngine): self.web3 = Web3(Web3.HTTPProvider('https://data-seed-prebsc-1-s1.binance.org:8545/')) self.strategyEngine = strategyEngine self.multiswap = self.web3.eth.contract( address=Web3.toChecksumAddress("0x1EF43774AbE961a1F3fDc547dfDD205fE766c091"), abi=abi)
def hello_world(self): nonce = self.web3.eth.getTransactionCount("0xD1B260aba3bA6f3D3099725b1b1C7cdD12581974") transaction = self.multiswap.functions.tokenTransfer( Web3.toChecksumAddress("0x521A72e54a88C49B36Ebce2A13Fa8e40184c6aD7"), Web3.toChecksumAddress("0x177C713E09cA2C5B703C05E40F3846dD77108f94"), int(0.001 * (10 ** 18)) ).buildTransaction({ 'gas': 241838, 'gasPrice': self.web3.toWei('10', 'gwei'), 'nonce': nonce, }) signed_tx = self.web3.eth.account.signTransaction(transaction, "private") txn_hash = self.web3.eth.sendRawTransaction(signed_tx.rawTransaction) print('txn_hash:', Web3.toHex(txn_hash))
if __name__ == '__main__': l = Multiswap(None) l.hello_world()
|