# How to Create Transaction and Send It to Blockchain
All events on the blockchain are represented as transactions. For example:
- data transaction writes data to an account data storage;
- transfer transaction moves a certain amount of the token from one account to another.
Waves provides variety of transaction types. See the Transaction Type article for more information. Depending on the type, transactions may contain different fields.
Transaction Proof
On Waves, each transaction can be sent only from the account. Transaction that is sent from ordinary account (without script) must contain a proof – sender's digital signature. (Smart accounts and dApps can set their own rules for verification of outgoing transations). See the Transaction Proof section for more information.
There are two options to sign a transaction:
- If your app sends trancastions on your behalf, you can use your own seed phrase or private key to sign transactions. This way is described in Sign Transaction Using Your Own Seed section below.
- If your app sends transactions on behalf of range of users, do not ask them for their seed phrases or private keys. Instead, use the interface to the wallet software. This way is described in Sign Transaction on Behalf of User section below.
Transaction Fee
Waves transactions are very cheap but not free. Each transaction must contain a fee not less than specified in Transaction fee article.
💡 On Testnet, a user can top up their WAVES balance using Testnet Faucet.
Workflow
In order to put a transaction on the blockchain, complete the following steps:
- Fill in the transaction fields.
- Sign transaction: generate sender's signature and add it to the transaction.
- Send transaction to a node.
You can send a request to your own node or to one of the Waves nodes with public API:
- Testnet: https://nodes-testnet.wavesnodes.com
- Mainnet: https://nodes.wavesnodes.com
The node checks transaction for validity. If a transaction is valid, then it is put to a generated block in the blockchain, if not — it's rejected by the blockchain. (Invoke script transactions and Exchange transactions can be saved on the blockchain even if the dApp script or the asset script failed, and a fee is charged for such transactions.)
# Sign Transaction Using Your Own Seed
# Using JavaScript
Use waves-transactions
library. Transaction proof is generated using your seed phrase. If transaction fee is not specified, it is calculated automatically.
See function descriptions in documentation on Github.
import { broadcast } from "@waves/waves-transactions";
import { data, transfer } from "@waves/waves-transactions";
const nodeUrl = 'https://nodes-testnet.wavesnodes.com';
const seed = 'insert your seed here';
// Data transaction: add records to the sender's account data storage
const records = [
{ key: 'integerVal', value: 1 },
{ key: 'booleanVal', value: true },
{ key: 'stringVal', value: 'Lorem ipsum dolor sit amet' }
]
const dataTx = data({ data: records }, seed); // Create and sign data transaction
broadcast(dataTx,nodeUrl).then(resp => console.log(resp));
// Transfer transaction: send 1 WAVES to the specified address
const money = {
recipient: '3N1HYdheNiiTtHgi2n3jLAek6N3H4guaciG',
amount: 100000000 // Actual amount multiplied by 10^decimals
}
const transferTx = transfer(money, seed); // Create and sign transfer transaction
broadcast(transferTx,nodeUrl).then(resp => console.log(resp));
# Using Python
The simplest way to send a transaction using Python is implementing PyWaves library developed by Waves community. Use Address
class to do the operations in blockchain. Explore more use cases in their readme file.
import pywaves as pw
myAddress = pw.Address(seed='insert your seed here')
data = [{'type':'string', 'key': 'stringVal', 'value':'Lorem ipsum dolor sit amet'},
{'type':'integer', key: 'integerVal', value: 1 },
{'type':'boolean', key: 'booleanVal', value: true }]
myAddress.dataTransaction(data)
myAddress.sendWaves(recipient = pw.Address('3P8pGyzZL9AUuFs9YRYPDV3vm73T48ptZxs'),
amount = 100000000)
# Sign Transaction on Behalf of User
# Using JavaScript
Use Signer
library together with ProviderWeb
and ProviderCloud
developed by the WX Network team. The provider opens a windows where user can confirm a transaction. After that the provider generates a transaction proof.
If transaction fee is not specified, it is calculated by Signer
automatically.
See full description in Signer documentation.
Example:
import { Signer } from '@waves/signer';
import { ProviderWeb } from '@waves.exchange/provider-web';
// Library initialization
const signer = new Signer({
NODE_URL: 'https://nodes-testnet.wavesnodes.com'
});
signer.setProvider(new ProviderWeb());
// Data transaction: add records to the sender's account data storage
const records = [
{ key: 'integerVal', value: 1 },
{ key: 'booleanVal', value: true },
{ key: 'stringVal', value: 'Lorem ipsum dolor sit amet' }
]
const dataTx = signer
.data({ data: records })
.broadcast();
dataTx.then(resp => console.log(resp));
console.log('Data tx: ' + dataTx);
// Transfer transaction: send 1 WAVES to the specified address
const money = {
recipient: '3N1HYdheNiiTtHgi2n3jLAek6N3H4guaciG',
amount: 100000000,
}
const transferTx = signer
.transfer(money)
.broadcast();
transferTx.then(resp => console.log(resp));