Comenzar
¡Emite tu primer activo en la red Stellar en una sola transacción!
- JavaScript
- Python
import {
Keypair,
Horizon,
TransactionBuilder,
Networks,
Operation,
Asset,
BASE_FEE,
} from "stellar-sdk";
const horizonUrl = "https://horizon-testnet.stellar.org";
const friendbotUrl = "https://friendbot.stellar.org";
const issuerKeypair = Keypair.random();
const destinationKeypair = Keypair.random();
console.log(
`issuer keys:\n${issuerKeypair.publicKey()}\n${issuerKeypair.secret()}\n`,
);
console.log(
`destination account keys:\n${issuerKeypair.publicKey()}\n${issuerKeypair.secret()}\n`,
);
await fetch(friendbotUrl + `?addr=${issuerKeypair.publicKey()}`); // pre-fund the `issuer` account using friendbot
await fetch(friendbotUrl + `?addr=${destinationKeypair.publicKey()}`); // pre-fund the `destination` account using friendbot
const server = new Horizon.Server(horizonUrl);
const account = await server.loadAccount(issuerKeypair.publicKey());
const abcAsset = new Asset("ABC", issuerKeypair.publicKey());
const transaction = new TransactionBuilder(account, {
fee: BASE_FEE,
networkPassphrase: Networks.TESTNET,
})
.addOperation(
Operation.changeTrust({
asset: abcAsset,
source: destinationKeypair.publicKey(),
}),
)
.addOperation(
Operation.payment({
destination: destinationKeypair.publicKey(),
asset: abcAsset,
amount: "100",
}),
)
.setTimeout(30)
.build();
transaction.sign(issuerKeypair, destinationKeypair);
const res = await server.submitTransaction(transaction);
console.log(`transaction hash:\n${res.hash}`);
import requests
from stellar_sdk import Asset, Keypair, Network, Server, TransactionBuilder
horion_url = "https://horizon-testnet.stellar.org"
friendbot_url = "https://friendbot.stellar.org"
issuer_keypair = Keypair.random()
destination_keypair = Keypair.random()
print(f"issuer keys:\n{issuer_keypair.public_key}\n{issuer_keypair.secret}\n")
print(f"issuer keys:\n{destination_keypair.public_key}\n{destination_keypair.secret}\n")
requests.get(f"{friendbot_url}?addr={issuer_keypair.public_key}")
requests.get(f"{friendbot_url}?addr={destination_keypair.public_key}")
server = Server('https://horizon-testnet.stellar.org')
account = server.load_account(issuer_keypair.public_key)
abc_asset = Asset('ABC', issuer_keypair.public_key)
transaction = (
TransactionBuilder(
source_account=account,
network_passphrase=Network.TESTNET_NETWORK_PASSPHRASE,
base_fee=100,
)
.append_change_trust_op(
asset=abc_asset,
source=destination_keypair.public_key,
)
.append_payment_op(
destination=destination_keypair.public_key,
amount='100',
asset=abc_asset,
)
.set_timeout(30)
.build()
)
transaction.sign(issuer_keypair)
transaction.sign(destination_keypair)
res = server.submit_transaction(transaction)
print(f"Transaction hash:\n{res['hash']}")