Exemple #1
0
def lb_tranfer(pvkey, toAddr, amount, gasLimit=None, gasPrice=None):
    acc = getAccount(pvkey)
    if acc:
        w3 = getW3()

        if gasLimit is None:
            gasLimit = 21000

        if gasPrice is None:
            gasPrice = w3.eth.gasPrice

        _from = acc.address
        _from_balance = w3.eth.getBalance(_from)
        # print('from余额', _from_balance)
        param = {
            'from': to0x(_from),
            'nonce': w3.eth.getTransactionCount(_from),
            'gasPrice': int(gasPrice),
            'gas': int(gasLimit),
            'to': w3.toChecksumAddress(to0x(toAddr)),
            'value': amount,
            # 'value': w3.toWei(amount, 'ether'),
            # data:b'',
        }
        print('交易参数 ', param)
        signed_txn = w3.eth.account.signTransaction(param, pvkey)
        hash_tx = w3.eth.sendRawTransaction(signed_txn.rawTransaction).hex()

        print('交易哈希 ', hash_tx)
        return hash_tx
    return None
Exemple #2
0
def token_balance(cttAddr, address):
    address = to0x(address)
    cttAddr = to0x(cttAddr)

    contract = getContract(cttAddr)
    w3 = getW3()
    address = w3.toChecksumAddress(address)
    balance = contract.functions.balanceOf(address).call()
    if balance is None:
        return 0
    return balance
Exemple #3
0
def token_tranfer(cttAddr,
                  pvkey,
                  toAddr,
                  tokenAmt,
                  gasLimit=None,
                  gasPrice=None,
                  nonce=None):
    cttAddr = to0x(cttAddr)
    c = getContract(cttAddr)
    w3 = getW3()
    acc = getAccount(pvkey)

    if c is None:
        return None

    if nonce is None:
        nonce = w3.eth.getTransactionCount(acc.address),

    if gasLimit is None:
        gasLimit = 80000

    if gasPrice is None:
        gasPrice = w3.eth.gasPrice

    if acc and tokenAmt > 0:
        fromAddr = w3.toChecksumAddress(to0x(acc.address))
        toAddr = w3.toChecksumAddress(to0x(toAddr))
        param = {
            'from': fromAddr,
            'value': 0,
            'gas': int(gasLimit),
            'gasPrice': int(gasPrice),
            'nonce': int(nonce[0]),
            # 'chainId': 1,
        }

        # print('toAddr', toAddr)
        # print('tokenAmt', tokenAmt)
        # print('TOKEN 交易参数 ', param)

        unicorn_txn = c.functions.transfer(toAddr,
                                           tokenAmt).buildTransaction(param)
        signed_txn = w3.eth.account.signTransaction(unicorn_txn,
                                                    private_key=acc.privateKey)
        hash_tx = w3.eth.sendRawTransaction(signed_txn.rawTransaction).hex()
        # print('TOKEN 交易哈希 ', hash_tx)
        return hash_tx
    return None
Exemple #4
0
def lb_balance(address):
    w3 = getW3()
    address = w3.toChecksumAddress(to0x(address))
    ac_balance = w3.eth.getBalance(address)
    if ac_balance is None:
        return 0
    return ac_balance
Exemple #5
0
def token_transList(cttAddr, num=10):

    url = '{}/api/contract_orderList?page=1&nums={}&str={}'.format(
        blockUrl, num, to0x(cttAddr))
    response = requests.get(url)
    if response.status_code != 200:
        return None

    data = response.json()
    return data['data'], data['nums']
Exemple #6
0
def decimals(cttAddr):
    contract = getContract(to0x(cttAddr))
    return contract.functions.decimals().call()
Exemple #7
0
def totalSupply(cttAddr):
    contract = getContract(to0x(cttAddr))
    return contract.functions.totalSupply().call()
Exemple #8
0
def symbol(cttAddr):
    contract = getContract(to0x(cttAddr))
    return contract.functions.symbol().call()
Exemple #9
0
def name(cttAddr):
    contract = getContract(to0x(cttAddr))
    return contract.functions.name().call()