要解决不支持Stellar-core交易的问题,您需要使用Horizon API来处理和提交交易。以下是一个使用JavaScript的代码示例:
const StellarSdk = require('stellar-sdk');
// 创建StellarSdk服务器对象
const server = new StellarSdk.Server('https://horizon.stellar.org');
// 创建发送交易的账户
const sourceKey = StellarSdk.Keypair.fromSecret('<<您的私钥>>');
const sourcePublicKey = sourceKey.publicKey();
// 创建接收交易的账户
const destinationId = '<<接收账户的公钥>>';
// 加载账户的最新信息
server.loadAccount(sourcePublicKey)
.then(function(sourceAccount) {
// 构建交易操作
const transaction = new StellarSdk.TransactionBuilder(sourceAccount)
.addOperation(StellarSdk.Operation.payment({
destination: destinationId,
asset: StellarSdk.Asset.native(),
amount: '10' // 发送10个Lumens
}))
.build();
// 对交易进行签名
transaction.sign(sourceKey);
// 提交交易到Horizon服务器
return server.submitTransaction(transaction);
})
.then(function(result) {
console.log('Transaction successful with hash: ', result.hash);
})
.catch(function(error) {
console.error('Transaction failed with error: ', error);
});
您需要将<<您的私钥>>
替换为发送交易账户的私钥,将<<接收账户的公钥>>
替换为接收交易账户的公钥。然后,使用适当的Horizon服务器URL(例如:https://horizon.stellar.org
)创建StellarSdk.Server
对象。
这段代码将创建一个支付操作,将10个Lumens发送到指定的接收账户,并在Horizon服务器上提交交易。如果交易成功,将打印出交易哈希值。如果交易失败,将打印出错误信息。
请注意,您需要安装stellar-sdk
库来运行此代码。您可以使用npm安装它:
npm install stellar-sdk
希望这可以帮助到您!