Пример #1
0
 def __init__(self,
              address: str,
              private_key: str,
              eth_client: EthClient = EthClient(network="mainnet")):
     self.address = address
     self.private_key = private_key
     self.eth_client = eth_client
Пример #2
0
import eth_utils

import defaults
import eth_tokens
from uniswap.uniswap import UniswapV2Client
from eth_client import EthClient
from erc_20_token import Erc20Token
from configparser import ConfigParser

cfg = ConfigParser()
cfg.read("app.ini")
privateKey = cfg.get('main', 'privateKey')
address = cfg.get('main', 'address')

print("读取账户成功:", address)
ethClient = EthClient(network="mainnet")

uniSwap = UniswapV2Client(address=address,
                          private_key=privateKey,
                          provider=defaults.CONF_MAINNET.get("http"))

ROOM = Erc20Token(contract_address=eth_tokens.TOKEN_ROOM, web3=ethClient.web3)
USDT = Erc20Token(contract_address=eth_tokens.TOKEN_USDT, web3=ethClient.web3)
WETH = Erc20Token(contract_address=eth_tokens.TOKEN_WETH, web3=ethClient.web3)

# 设置gas价格
uniSwap.gasPrice = eth_utils.to_wei(50, "gwei")

IN_TOKEN = USDT
OUT_TOKEN = ROOM
Пример #3
0
            'gas': gas_limit,
            'gasPrice': eth_utils.to_wei(gas_price, "gwei"),
            'nonce': self._web3.eth.getTransactionCount(from_address),
            'from': from_address
        }
        transfer_txn = self.contract.functions.transferFrom(from_address, to_address, token_id).buildTransaction(txn)

        signed_tran = self._web3.eth.account.sign_transaction(transfer_txn, private_key=private_key)
        tran_hash = self._web3.eth.sendRawTransaction(signed_tran.rawTransaction)
        return TransactionRet(tran_hash=tran_hash, web3=self._web3)

    def transfer(self, from_address: str, private_key: str, to_address: str, amount, gas_price: float,
                 gas_limit: int = 21000):
        txn = {
            'chainId': self.chain_id,
            'gas': gas_limit,
            'gasPrice': eth_utils.to_wei(gas_price, "gwei"),
            'nonce': self._web3.eth.getTransactionCount(from_address),
            'from': from_address
        }
        transfer_txn = self.contract.functions.transfer(to_address, int(amount)).buildTransaction(txn)

        signed_tran = self._web3.eth.account.sign_transaction(transfer_txn, private_key=private_key)
        tran_hash = self._web3.eth.sendRawTransaction(signed_tran.rawTransaction)
        return TransactionRet(tran_hash=tran_hash, web3=self._web3)


if __name__ == '__main__':
    client = EthClient(network="bsc-test")
    # dego erc721 测试环境 0x6657dce81eed831c728281dbf5d973ecdfa219dc
Пример #4
0
    default=21000,
    help="指定每次交易需要的gas,默认是21000")

parser.add_argument(
    "--gas-price",
    type=int,
    help="指定每次交易的gas价格,价格越高越容易成交")

parser.add_argument(
    "--contract",
    type=str,
    default="0x9765fea9752505a685c1bce137ae5b2efe8ddf62",
    help="空投的合约地址")

argv = parser.parse_args()
client = EthClient(network=argv.network)

CONTRACT_ADDRESS = Web3.toChecksumAddress(argv.contract)
contract = client.web3.eth.contract(address=CONTRACT_ADDRESS, abi=ABI)

def _clearProgress(command):
    file = "./data/" + command + ".txt"
    if os.path.exists(file):
        os.remove(file)


def _saveProgress(command, lastAddress):
    with open("./data/" + command + ".txt", 'w') as f:
        f.write(lastAddress)

Пример #5
0
import eth_utils
from decimal import Decimal
import defaults
import bsc_tokens
from bakeryswap.bakeryswap import BakerySwapV2Client
from eth_client import EthClient
from erc_20_token import Erc20Token

cfg = ConfigParser()
cfg.read("app.ini")
privateKey = cfg.get('main', 'privateKey')
address = cfg.get('main', 'address')

print("读取账户成功:", address)
ethClient = EthClient(network="bsc")

bakeryswap = BakerySwapV2Client(address=address,
                                private_key=privateKey,
                                provider=defaults.CONF_BSC.get("http"))

USDT = Erc20Token(contract_address=bsc_tokens.TOKEN_USDT, web3=ethClient.web3)
BUSD = Erc20Token(contract_address=bsc_tokens.TOKEN_BUSD, web3=ethClient.web3)
WBNB = Erc20Token(contract_address=bsc_tokens.TOKEN_WBNB, web3=ethClient.web3)

# 设置gas价格
bakeryswap.gasPrice = eth_utils.to_wei(10, "gwei")

vaiBalance = USDT.balanceOf(address)
vaiBalanceInHuman = USDT.inHumanNum(vaiBalance)
# 交易滑点
Пример #6
0
import time

from web3 import Web3

from eth_client import EthClient
from configparser import ConfigParser

parser = argparse.ArgumentParser()

cfg = ConfigParser()
cfg.read("app.ini")
privateKey = cfg.get('main', 'privateKey')
address = cfg.get('main', 'address')

print("读取账户成功:", address)
ethClient = EthClient(network="bsc")

bidos_addr = "0x6Ea4fd26f9E0Ba1BCAc8519Bd7D69296e32F9157"


parser.add_argument(
    "--count",
    type=int,
    default=10,
    help="执行次数")


parser.add_argument(
    "--gas-price",
    type=int,
    default=5,