[英]How to sign and send transfer transaction using waves-transaction JS library?
Please help me understand https://testnodes.wavesnodes.com/api-docs/index.html I use this api and this library https://github.com/wavesplatform/waves-transactions I cannot send a transaction using the manual to the library or directly by POST request for api.请帮助我理解https://testnodes.wavesnodes.com/api-docs/index.html我使用这个 api 和这个库https://github.com/wavesplatform/waves-transactions我无法使用手册发送交易库或直接通过 POST 请求获取 api。
common mistakes:常见错误:
Error: State check failed.错误:状态检查失败。 Reason: Script doesn't exist and proof
原因:脚本不存在并证明
Error: State check failed.错误:状态检查失败。 Reason: Transactions from non-scripted accounts must have exactly 1 proof
原因:来自非脚本账户的交易必须恰好有 1 个证明
A POST request for url / addresses also gives an error.对 url / 地址的 POST 请求也会出错。 Provided API key is not correct.
提供的 API 密钥不正确。 Here is my code:
这是我的代码:
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));
If you use Waves transactions api, the request should be signed already and you can post it to /transactions/broadcast.如果您使用 Waves 交易 api,则该请求应该已经签名,您可以将其发布到 /transactions/broadcast。 Then you don't need your own node and you don't need your own API Key.
那么你不需要自己的节点,也不需要自己的 API Key。 in your code, I see several mistakes here:
在您的代码中,我在这里看到了几个错误:
const nodeUrl = "https://testnodes.wavesnodes.com/";
const nodeUrl = "https://testnodes.wavesnodes.com/";
Here is the code:这是代码:
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));
[Update] [更新]
The above code working good.上面的代码运行良好。 Just a quick update since I see the new testnet URI is below link:
只是一个快速更新,因为我看到新的 testnet URI 在链接下面:
https://nodes-testnet.wavesnodes.com https://nodes-testnet.wavesnodes.com
I mean I have replace from https://testnodes.wavesnodes.com to https://nodes-testnet.wavesnodes.com then it's working maybe because we created the account from the different place.我的意思是我已经从https://testnodes.wavesnodes.com替换为https://nodes-testnet.wavesnodes.com然后它可以工作,也许是因为我们从不同的地方创建了帐户。
So this is the final code:所以这是最终的代码:
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.