Exemplo n.º 1
0
    'value': origin_balance_from - 21000,
    'gas': 21000,
    'gasPrice': 1,
    'data': b'',
    'to': bytearray.fromhex(to_address1)
})
raw_tx2, tx_hash2 = acc_from.sign({
    'nonce': 2,
    'value': origin_balance_from - 21000,
    'gas': 21000,
    'gasPrice': 1,
    'data': b'',
    'to': bytearray.fromhex(to_address2)
})
cli.sendTransactions({tx_hash1: raw_tx1, tx_hash2: raw_tx2})

while True:
    receipts = cli.getTransactionReceipts([tx_hash1, tx_hash2])
    if receipts is None or len(receipts) != 2:
        time.sleep(1)
        continue
    break

new_balance_from = cli.getBalance(acc_from.address())
new_balance_to1 = cli.getBalance(to_address1)
new_balance_to2 = cli.getBalance(to_address2)
print('After transfer:')
print(f'\tBalance of {acc_from.address()}: {new_balance_from}')
print(f'\tBalance of {to_address1}: {new_balance_to1}')
print(f'\tBalance of {to_address2}: {new_balance_to2}')
coo = Account(coo_private_key)
user1 = Account(user_private_key)
user2_address = '230DCCC4660dcBeCb8A6AEA1C713eE7A04B35cAD'

raw_tx, tx_hash = coo.sign(
    kitty_core_contract.functions.createPromoKitty(
        0, user1.address()).buildTransaction({
            'gas': 1000000,
            'gasPrice': 1,
        }))
cli.sendTransactions({tx_hash: raw_tx})

receipts = []
while True:
    receipts = cli.getTransactionReceipts([tx_hash])
    if receipts is None or len(receipts) != 1:
        time.sleep(1)
        continue
    break
events = kitty_core_contract.processReceipt(receipts[0])
new_kitty = events['Birth']['kittyId']
print(
    f'New kitty {new_kitty} born and assigned to {events["Birth"]["owner"][24:]}'
)

raw_tx, tx_hash = user1.sign(
    kitty_core_contract.functions.transfer(user2_address,
                                           new_kitty).buildTransaction({
                                               'gas':
                                               1000000,