如何使用wave-transaction JS库签署和发送转移交易?

时间:2019-03-27 14:50:07

标签: javascript blockchain wavesplatform

请帮助我了解https://testnodes.wavesnodes.com/api-docs/index.html我使用了这个api和这个库https://github.com/wavesplatform/waves-transactions 我无法使用手册将交易发送到库,也不能直接通过api的POST请求发送交易。

常见错误:

  • 错误:状态检查失败。原因:脚本不存在且无法证明

  • 错误:状态检查失败。原因:来自非脚本帐户的交易必须具有准确的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));

2 个答案:

答案 0 :(得分:1)

如果您使用Waves交易api,则该请求应该已经签名,您可以将其发布到/ transactions / broadcast。然后,您不需要自己的节点,也不需要自己的API密钥。 在您的代码中,我在这里看到一些错误:

  1. 您正在使用testnet节点转移到MAINNET地址。您 应该改用TESTNET地址。在recepent改变 地址到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));

答案 1 :(得分:0)

[更新]

以上代码运行良好。只是快速更新,因为我在链接下面看到了新的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));