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

1.1k views Asked by At

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.

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

A POST request for url / addresses also gives an error. Provided API key is not correct. 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));
2

There are 2 answers

0
Nazim Faour On BEST ANSWER

If you use Waves transactions api, the request should be signed already and you can post it to /transactions/broadcast. Then you don't need your own node and you don't need your own API Key. in your code, I see several mistakes here:

  1. You're transferring to MAINNET address using testnet node. you should use TESTNET address instead. in the reciepent change the address to an address in testnet and let me know if you still get any errors. you can create new accounts here https://testnet.ide.wavesplatform.com/ in the tab accounts on the top right.
  2. Use https instead of http, const nodeUrl = "https://testnodes.wavesnodes.com/";
  3. Add the chain id('T' for testnet and 'W' for mainnet)

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));
0
Ayoung On

[Update]

The above code working good. Just a quick update since I see the new testnet URI is below link:

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.

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));