![](/img/trans.png)
[英]How can I sign a transaction with a private key using the REST API Waves?
[英]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。 在您的代碼中,我在這里看到了幾個錯誤:
const nodeUrl = "https://testnodes.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://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.