I run a validator node on the public network for which I need to create an account. Hence, I started by creating a Stellar account in the test network as described here. So far so good.
As per my understanding, I can now create additional accounts using this account by using the TransactionBuilder
and CreateAccount
functions. So based on the documentation of the TransationBuilder and this example I ended up with the following code.
from stellar_sdk.keypair import Keypair
from stellar_sdk.network import Network
from stellar_sdk.server import Server
from stellar_sdk.transaction_builder import TransactionBuilder
from stellar_sdk.exceptions import NotFoundError, BadResponseError, BadRequestError
server = Server("https://horizon-testnet.stellar.org")
source_key = Keypair.from_secret("SXXXX") # Account in test network
# Thew new account's public key = my validator's public key
destination_id = "GXXXXX"
source_account = server.load_account(source_key.public_key)
base_fee = server.fetch_base_fee()
# Start building the transaction.
transaction = (
TransactionBuilder(
source_account=source_account,
network_passphrase=Network.PUBLIC_NETWORK_PASSPHRASE,
base_fee=base_fee,
)
.append_create_account_op(destination=destination_id, starting_balance="10")
# Wait a maximum of three minutes for the transaction
.set_timeout(180)
.build()
)
Network.public_network()
transaction.sign(source_key)
try:
# And finally, send it off to Stellar!
response = server.submit_transaction(transaction)
print(f"Response: {response}")
except (BadRequestError, BadResponseError) as err:
print(f"Something went wrong!\n{err}")
The program exits with the error below. A similar question on this site was solved by adding the public network line before signing the transaction.
Something went wrong!
{
"type": "https://stellar.org/horizon-errors/transaction_failed",
"title": "Transaction Failed",
"status": 400,
"detail": "The transaction failed when submitted to the stellar network. The `extras.result_codes` field on this response contains further details. Descriptions of each code can be found at: https://www.stellar.org/developers/guides/concepts/list-of-operations.html",
"extras": {
"envelope_xdr": "AAAAADx4IYtDyD1GcNQMLowZLkxHGWFCa2pDpVl/t2wEDNPtAAAAZAAQCjsAAAABAAAAAQAAAAAAAAAAAAAAAF6Jq9EAAAABAAAAF0NyZWF0aW5nIGFjYyB0cmFuc2F0aW9uAAAAAAEAAAAAAAAAAAAAAAAiqAyTZW5SpZuTDf/IS+zflveRXANlVd7uVU2AyJh7UQAAAAAF9eEAAAAAAAAAAAEEDNPtAAAAQHZ0sr4K6oxvJq+HowKpQjz4z8pCxTZiZn/JtBaouqxJB9HOS1JHI5zMwOuhge+Tf2j75ntb5KcDBAkVxUb7MQg=",
"result_codes": {
"transaction": "tx_bad_auth"
},
"result_xdr": "AAAAAAAAAGT////6AAAAAA=="
}
}
What am I doing wrong? Is my approach/understanding maybe just fundamentally wrong?