javascript - 无法将 Ripple (Cryptocurrency Coin - XRP) 发送到钱包
问题描述
我正在尝试使用以下代码将波纹(加密货币)-XRP 发送到另一个地址,但我收到以下错误:
“未捕获(承诺)错误:水龙头 URL 未定义或无法推断。”
在 HTML 文件中包含以下 JS 引用,
脚本 src="https://unpkg.com/xrpl@2.0.0/build/xrpl-latest-min.js" 脚本类型="应用程序/javascript" src="send-xrp.js"
我错过了什么???
发送-xrp.js ===========
// Dependencies for Node.js.
// In browsers, use a <script> tag instead.
if (typeof module !== "undefined") {
// Use var here because const/let are block-scoped to the if statement.
var xrpl = require('xrpl')
}
// Example credentials
const wallet = xrpl.Wallet.fromSeed("I ENTERED MY SECRET KEY HERE")
console.log(wallet.address)
// Connect -------------------------------------------------------------------
async function main() {
console.log("Connecting to Testnet... I CHANGED BELOW TO PRODUCTION NETWORK")
const client = new xrpl.Client('wss://xrplcluster.com')
await client.connect()
// Get credentials from the Testnet Faucet -----------------------------------
console.log("Getting a wallet from the Testnet faucet...")
const {wallet, balance} = await client.fundWallet()
// Prepare transaction -------------------------------------------------------
const prepared = await client.autofill({
"TransactionType": "Payment",
"Account": wallet.address,
"Amount": xrpl.xrpToDrops("35"),
"Destination": "ENTERED MY DESTINATION KEY HERE"
})
const max_ledger = prepared.LastLedgerSequence
console.log("Prepared transaction instructions:", prepared)
console.log("Transaction cost:", xrpl.dropsToXrp(prepared.Fee), "XRP")
console.log("Transaction expires after ledger:", max_ledger)
// Sign prepared instructions ------------------------------------------------
const signed = wallet.sign(prepared)
console.log("Identifying hash:", signed.hash)
console.log("Signed blob:", signed.tx_blob)
// Submit signed blob --------------------------------------------------------
const tx = await client.submitAndWait(signed.tx_blob)
// Wait for validation -------------------------------------------------------
// submitAndWait() handles this automatically, but it can take 4-7s.
// Check transaction results -------------------------------------------------
console.log("Transaction result:", tx.result.meta.TransactionResult)
console.log("Balance changes:", JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2))
// End of main()
client.disconnect()
}
main()
解决方案
“密钥”或privateKey
用于签署与seed
. 此外,您似乎正在连接到主网而不是测试网尝试:
const wallet = xrpl.Wallet.fromSeed(seed)
const client = new xrpl.Client(`wss://s.altnet.rippletest.net:51233`)
推荐阅读
- r - 具有生成回归器的 2SLS,第一阶段校正
- laravel - Laravel - local.ERROR:ErrorException:不应静态调用非静态方法 Illuminate\Database\Eloquent\Model::update()
- swift - 快速导入私有框架
- mysql - 从 MySQL 中的嵌套 JSON 中提取值
- linux - 非root用户如何在特权端口上运行
- javascript - 如何从 Firestore 中的多层文档中获取字段
- java - 有没有办法指定用于在maven中编译依赖项目的JDK版本?
- powershell - 在文件夹中查找最新文件
- amazon-web-services - 在 AWS 中设置 Datapipeline 流
- javascript - 如何在ejs中设置if else条件