簡體   English   中英

如何使用 wave-transaction JS 庫簽署和發送轉賬交易?

[英]How to sign and send transfer transaction using waves-transaction JS library?

請幫助我理解https://testnodes.wavesnodes.com/api-docs/index.html我使用這個 api 和這個庫https://github.com/wavesplatform/waves-transactions我無法使用手冊發送交易庫或直接通過 POST 請求獲取 api。

常見錯誤:

  • 錯誤:狀態檢查失敗。 原因:腳本不存在並證明

  • 錯誤:狀態檢查失敗。 原因:來自非腳本賬戶的交易必須恰好有 1 個證明

對 url / 地址的 POST 請求也會出錯。 提供的 API 密鑰不正確。 這是我的代碼:

const { transfer, broadcast } = require("@waves/waves-transactions");
const seed =
  "ride flee tenant tuna share buyer work west amateur review time kick";
const signedTranserTx = transfer(
  {
    amount: 1,
    recipient: "3NBVqYXrapgJP9atQccdBPAgJPwHDKkh6A8"
  },
  seed
);
const nodeUrl = "http://testnodes.wavesnodes.com";

broadcast(signedTranserTx , nodeUrl)
  .then(resp => console.log(resp))
  .catch(err => console.error(err));

如果您使用 Waves 交易 api,則該請求應該已經簽名,您可以將其發布到 /transactions/broadcast。 那么你不需要自己的節點,也不需要自己的 API Key。 在您的代碼中,我在這里看到了幾個錯誤:

  1. 您正在使用 testnet 節點轉移到 MAINNET 地址。 您應該改用 TESTNET 地址。 在 reciepent 中將地址更改為 testnet 中的地址,如果您仍然遇到任何錯誤,請告訴我。 您可以在https://testnet.ide.wavesplatform.com/在右上角的選項卡帳戶中創建新帳戶。
  2. 使用 https 代替 http, const nodeUrl = "https://testnodes.wavesnodes.com/";
  3. 添加鏈 id('T' 代表測試網,'W' 代表主網)

這是代碼:

const { transfer, broadcast } = require("@waves/waves-transactions");
const seed =
"ride flee tenant tuna share buyer work west amateur review time kick";
const signedTranserTx = transfer(
  {
    amount: 100,
    recipient: "3N3pJ8xAnbaSBFdAbnaKe4yu4ZXbYkatMcN"
  },
  seed
);
const nodeUrl = "https://testnodes.wavesnodes.com";
broadcast({ ...signedTranserTx, chainId: "T" }, nodeUrl)
  .then(resp => console.log(resp))
  .catch(err => console.error(err));

[更新]

上面的代碼運行良好。 只是一個快速更新,因為我看到新的 testnet URI 在鏈接下面:

https://nodes-testnet.wavesnodes.com

我的意思是我已經從https://testnodes.wavesnodes.com替換為https://nodes-testnet.wavesnodes.com然后它可以工作,也許是因為我們從不同的地方創建了帳戶。

所以這是最終的代碼:

const { transfer, broadcast } = require("@waves/waves-transactions");
const seed =
"ride flee tenant tuna share buyer work west amateur review time kick";
const signedTranserTx = transfer(
  {
    amount: 100,
    recipient: "3N3pJ8xAnbaSBFdAbnaKe4yu4ZXbYkatMcN"
  },
  seed
);
const nodeUrl = "https://nodes-testnet.wavesnodes.com";
broadcast({ ...signedTranserTx, chainId: "T" }, nodeUrl)
  .then(resp => console.log(resp))
  .catch(err => console.error(err));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM