Transfer funds

Let’s learn by example.

Throughout this tutorial, we’ll walk you through the creation of a basic script to transfer funds from an account to another.

It’ll consist of three parts:

  • Generate 2 accounts via command line client
  • Get some funds for the first account
  • Transfer the funds from an account to the other

We’ll assume you have the SDK installed already. You can tell the SDK is installed and which version by running the following command in a shell prompt (indicated by the $ prefix):

$ aecli --version

First step will be to generate two new accounts using the command line client:

First import the required libraries


from aeternity.node import NodeClient, Config
from aeternity.signing import Account
from aeternity import utils
import os

Then instantiate the node client and generate 2 accounts


NODE_URL = os.environ.get('TEST_URL', 'https://testnet.aeternity.io')

node_cli = NodeClient(Config(
    external_url=NODE_URL,
    blocking_mode=True,
))

# generate ALICE account 
alice = Account.generate()

# generate BOB account
bob = Account.generate()

# retrieve the balances for the accounts
bob_balance = node_cli.get_balance(bob)
alice_balance = node_cli.get_balance(alice)

# print the balance of the two accounts
print(f"Alice address is {alice.get_address()}")
print(f"with balance {utils.format_amount(alice_balance)}")
print(f"Bob address is {bob.get_address()}")
print(f"with balance {utils.format_amount(bob_balance)}")

Now copy the Alice address and paste it into the Aeternity Faucet to top up the account; once the Alice account has some positive balance we can execute the spend transaction:


#TODO pause the execution while using the faucet
# execute the spend transaction
tx = node_cli.spend(alice, bob.get_address(), "3AE")
print(f"transaction hash: {tx.hash}")
print(f"inspect transaction at {NODE_URL}/v2/transactions/{tx.hash}")

And finally verify the new balance:


# retrieve the balances for the accounts
bob_balance = node_cli.get_balance(bob)
alice_balance = node_cli.get_balance(alice)

print(f"Alice balance is {utils.format_amount(alice_balance)}")
print(f"Bob balance is {utils.format_amount(bob_balance)}")

Thats it! You have successfully executed your transaction in the Aeternity Blockchain testnet network. For the mainnet network the procedure is the same except you will have to get some tokens via an exchange or via other means.