JS libraries (choose network, tokens, store/read/change data etc.)


#1

Hello colleagues!
My purpose is to save some data X inside the blockchain and then read and “change” it.
Could someone explain what is technically mean if I send ‘data’ transaction more that once:

const { data } = require(‘waves-transactions’)
const signedDataTx = data(previousSignedDataTx)

Can I use this way to save my data inside the blockchain and then ‘change’ it multiple times?
Can I see the data transaction history for corresponding account?

Also, I want to create my own token. I’ve called:

 const generator = require('@waves/signature-generator');
 const transactions = require('@waves/waves-transactions');
 generator.config.set({ networkByte: generator.TESTNET_BYTE }); 
 const issueData = {
       name: 'TEST',
       description: 'TEST description',
       quantity: 10000000000,
       precision: 0,
       reissuable: true,// additional emission is possible
       timestamp: Date.now()
 };
 const signedIssueTx = transactions.issue(issueData, seedMain);

but I do not see any tokens and transaction here (for my ‘seedMain’ account):
https://testnet.wavesplatform.com/wallet/transactions
What I did wrong?


#2

Hello!

Basically Data transaction is a key-value update for the data storage of the account. The first data transaction creates a key-value storage attached to the account and puts its keys and values in this storage. The following data transactions will update values of existing keys or add new key-value pairs to the account’s storage.
Removing of the key is not possible using the data transaction. The only way is to set the empty value to the key.
So, yes, you can add and update the key-value storage in blockchain.
All transactions are stored in blockchain, so the full history of data updates always here. Maybe there is no API for this. But you always can fetch all transactions for the account.

I don’t know exactly how JS library works, but maybe you haven’t send the transaction to the node?


#3

Alexey, thank you for detailed explanation:+1:
Concerning testnet, I do not fully understand what I must set to send transactions into testnet and where I can see them.
I just set network byte as I described above,

generator.config.set({ networkByte: generator.TESTNET_BYTE });

maybe I have to set URL for testnet and node? I do not know, I do not see any documentation concerning it(
So, I see
https://pool.testnet.wavesnodes.com
inside the settings my wallet here https://testnet.wavesplatform.com/wallet/transactions

I suppose I do not set some urls. If you describe how it works I will be very grateful.
I’m writing JS code and want to easy change network (main/test) and view transactions inside both.


#4

In addition, inside the deprecated waves-api library I’ve found:

export const DEFAULT_MAINNET_CONFIG: IWavesConfig = {
    ...DEFAULT_BASIC_CONFIG,
    networkByte: MAINNET_BYTE,
    nodeAddress: 'https://nodes.wavesplatform.com',
    matcherAddress: 'https://matcher.wavesplatform.com/matcher'
};

export const DEFAULT_TESTNET_CONFIG: IWavesConfig = {
    ...DEFAULT_BASIC_CONFIG,
    networkByte: TESTNET_BYTE,
    nodeAddress: 'https://testnet1.wavesnodes.com',
    matcherAddress: 'https://testnet1.wavesnodes.com/matcher'
};

But it is really unclear for me how I can use it for new libraries waves-transactions and waves-signature-adapter


#5

Please check the documentation at https://docs.wavesplatform.com/en/development-and-api/client-libraries.html.

To create the transaction you have to do following steps:

  1. Create a transaction object of desired type
  2. Sign the transaction
  3. Broadcast the transaction to the network using the node’s API method POST transactions/broadcast

The networkByte affects some transactions and the address generation from public keys.
To sign a transaction use the correct private key, the key that was used to generate your address.
To broadcast transaction simply post it’s JSON to any public node.


#6

Alexey, thank you,
I want to use JS libs instead of REST API, looks like I need someone, who knows how we can solve typical tasks (which are solvable using old library) with the new libraries for JavaScript.
Looks like I should set node URL and matcher URL?

The networkByte affects some transactions and the address generation from public keys.

My mistake is that I thought that inside the new libraries this flag chooses network:(

So, despite everything, I cannot find how to set network config for new libraries as it easy can be set for not maintained waves-api.

Added:
After some additional help from Discord group I’ve understood that new libraries like waves-transactions are local and do not require network configuration and for each transaction I have to call REST “transactions/broadcast” end-point.
It is really as easy as unclear:-) Please add some words to docs for people like me)


#7

@alexey.kiselev Alexey, how can I get latest=current storage state (after a lot of data transaction, which change some values separately)?
So, my task is change state multiple times then read it to make some calculations off-chain.


#8

Use API methods addresses/data/{address} and addresses/data/{address}/{key}. The first one will return the complete account data state, the latter only the current value of the key.


#9

Thank you for great support!


#10

Alexey, another question in this thread, please.
I’ve sent data transaction in
https://pool.testnet.wavesnodes.com
In my wallet I see

but empty in “Sent” (“Отправленные” in Russian):

then I open transaction details

and do not see information in Explorer:
https://testnet.wavesexplorer.com/tx/6pii35Tx37APjRcChPE7ecsxUXJiTYKVzDm3sAv4AEi6
that is real problem for me.
Could you explain what happens and help me to see my transaction details without wallet (public)?


#11

Guys from the client dev team told me that in this case “sent” or “отправленные” means tokens sent out from your wallet. So, here you will see only outgoing transfer transactions. Data transactions should appear only on “All” page.


#12

Ok, but is it possible to see data transactions inside the Explorer?

This API allow anyone get my data via API, so, how it is possible via UI Web service like Explorer?

Added:
Looks like there is a problem with old Explorer, here
https://wavesexplorer.com/tx/6pii35Tx37APjRcChPE7ecsxUXJiTYKVzDm3sAv4AEi6
it works


#13

The old explorer is abandoned. Use the new one.