# Send Transactions
Send transactions after meeting the prerequisites.
# Prerequisites
- Wallet: Set up a wallet via Keeper Wallet or WX Network.
NOTE: Ensure saving your wallet's seed phrase to send transactions.
- Tokens: Obtain WAVES tokens to cover each transaction's fee:
- For the Mainnet network: Get at least 0.001 WAVES via Available Market Options.
- For the Testnet network: Get at least 0.001 WAVES via Faucet.
- For the Stagenet network: Get at least 0.001 WAVES via Faucet.
# Tutorial
Follow the instructions for the transaction type you want to send:
- Issue.
- Reissue.
- Burn.
- Transfer.
- Mass Transfer.
- Exchange.
- Lease.
- Lease Cancel.
- Create Alias.
- Data.
- Set Script.
- Set Asset Script.
- Update Asset Info.
- Invoke Script.
- Sponsor Fee.
# Issue
In your project directory:
- Replace the
waves.go
file code with the following snippet:package main // Necessary imports. import ( "bytes" "context" "encoding/binary" "fmt" "net/http" "time" "github.com/wavesplatform/gowaves/pkg/client" "github.com/wavesplatform/gowaves/pkg/crypto" "github.com/wavesplatform/gowaves/pkg/proto" ) func main() { /* Specify the network: - Mainnet: `proto.MainNetScheme` - Testnet: `proto.TestNetScheme` - Stagenet: `proto.StageNetScheme` */ const network = proto.TestNetScheme nodeClient, err := client.NewClient(client.Options{ /* Specify the link for the same network as mentioned above: - Mainnet: "https://nodes.wavesnodes.com/" - Testnet: "https://nodes-testnet.wavesnodes.com/" - Stagenet: "https://nodes-stagenet.wavesnodes.com/" */ BaseUrl: "https://nodes-testnet.wavesnodes.com/", Client: &http.Client{}, ChainID: network, }) // Print the error if caught. if err != nil { panic(err) } // Set the wallet parameters. const ( accountNumber = 0 // Account number in the wallet. Zero by default. // Specify the seed phrase of your wallet. seedPhrase = "PASTE YOUR SEED PHRASE" ) // Transform the wallet's seed phrase into the required format. accountNumConcatSeedPhrase := bytes.Join([][]byte{ binary.BigEndian.AppendUint32(nil, accountNumber), []byte(seedPhrase), }, nil) // Get the necessary details about the wallet's seed. accountSeed, err := crypto.SecureHash(accountNumConcatSeedPhrase) if err != nil { panic(err) } // Generate the key pair from the wallet's seed phrase. senderPrivateKey, senderPublicKey, err := crypto.GenerateKeyPair(accountSeed.Bytes()) if err != nil { panic(err) } // Current time in milliseconds. currentTime := uint64(time.Now().UnixMilli()) // Optional. Enter your asset's Ride script. rideScript := ` {-# STDLIB_VERSION 6 #-} {-# CONTENT_TYPE EXPRESSION #-} {-# SCRIPT_TYPE ASSET #-} func trueReturner () = { true } trueReturner() ` // Compile the Ride script. compiledScript, errList := compiler.Compile(rideScript, true, true) if errList != nil && len(errList) > 0 { // Check whether there were any errors during compilation. panic(fmt.Sprintf("Error compiling script: %v", errList)) } // Build an Issue transaction. createTx := proto.NewUnsignedIssueWithProofs( 2, // Transaction version. senderPublicKey, // Sender's public key. "TOKEN NAME", // Name. "TOKEN DESCRIPTION", // Description. uint64(9876543210), // Amount. byte(2), // Decimals. true, // Flag indicating whether the asset is reissuable. compiledScript, // Asset script or `nil`. currentTime, // Timestamp. 100000000, // Fee in WAVES in the smallest unit. E.g., `100000000` for 1 token. ) // Sign the transaction with the sender's private key. err = createTx.Sign(network, senderPrivateKey) if err != nil { panic(err) } // Context to cancel the request execution on timeout. contextcreateTx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() // Send the transaction to the node. _, err = nodeClient.Transactions.Broadcast(contextcreateTx, createTx) if err != nil { panic(err) } // Print the message if the transaction has been successfully sent. fmt.Printf("Transaction %q sent successfully\n", createTx.ID.String()) // Set the timeout to ensure the transaction has appeared on the blockchain. time.Sleep(5 * time.Second) // Get the information about the transaction from the node. createTxInfo, _, err := nodeClient.Transactions.Info(contextcreateTx, *createTx.ID) if err != nil { panic(err) } // Print the transaction info. fmt.Printf("Transaction info: %+v\n", createTxInfo) }
- Install the dependencies:
go mod tidy
- Run the application:
go run waves.go
# Reissue
NOTE: You can reissue only those asset that were issued by you with the reissuable flag set to
true
.
In your project directory:
- Replace the
waves.go
file code with the following snippet:package main // Necessary imports. import ( "bytes" "context" "encoding/binary" "fmt" "net/http" "time" "github.com/wavesplatform/gowaves/pkg/client" "github.com/wavesplatform/gowaves/pkg/crypto" "github.com/wavesplatform/gowaves/pkg/proto" ) func main() { /* Specify the network: - Mainnet: `proto.MainNetScheme` - Testnet: `proto.TestNetScheme` - Stagenet: `proto.StageNetScheme` */ const network = proto.TestNetScheme nodeClient, err := client.NewClient(client.Options{ /* Specify the link for the same network as mentioned above: - Mainnet: "https://nodes.wavesnodes.com/" - Testnet: "https://nodes-testnet.wavesnodes.com/" - Stagenet: "https://nodes-stagenet.wavesnodes.com/" */ BaseUrl: "https://nodes-testnet.wavesnodes.com/", Client: &http.Client{}, ChainID: network, }) // Print the error if caught. if err != nil { panic(err) } // Set the wallet parameters. const ( accountNumber = 0 // Account number in the wallet. Zero by default. // Specify the seed phrase of your wallet. seedPhrase = "PASTE YOUR SEED PHRASE" ) // Transform the wallet's seed phrase into the required format. accountNumConcatSeedPhrase := bytes.Join([][]byte{ binary.BigEndian.AppendUint32(nil, accountNumber), []byte(seedPhrase), }, nil) // Get the necessary details about the wallet's seed. accountSeed, err := crypto.SecureHash(accountNumConcatSeedPhrase) if err != nil { panic(err) } // Generate the key pair from the wallet's seed phrase. senderPrivateKey, senderPublicKey, err := crypto.GenerateKeyPair(accountSeed.Bytes()) if err != nil { panic(err) } // Current time in milliseconds. currentTime := uint64(time.Now().UnixMilli()) // Define the asset ID to be reissued. assetID, err := crypto.NewDigestFromBase58("PASTE THE ASSET ID") if err != nil { panic(err) } // Build a Reissue Еransaction. createTx := proto.NewUnsignedReissueWithSig( senderPublicKey, // Sender's public key. assetID, // Asset's ID. 100, // New token quantity in the smallest unit. E.g., `100` for 1. true, // New flag indicating whether the asset is reissuable. currentTime, // Current time. 100000000, // Fee in WAVES in the smallest unit. E.g., `100000000` for 1 token. ) // Sign the transaction with the sender's private key. err = createTx.Sign(network, senderPrivateKey) if err != nil { panic(err) } // Context to cancel the request execution on timeout. contextcreateTx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() // Send the transaction to the node. _, err = nodeClient.Transactions.Broadcast(contextcreateTx, createTx) if err != nil { panic(err) } // Print the message if the transaction has been successfully sent. fmt.Printf("Transaction %q sent successfully\n", createTx.ID.String()) // Set the timeout to ensure the transaction has appeared on the blockchain. time.Sleep(5 * time.Second) // Get the information about the transaction from the node. createTxInfo, _, err := nodeClient.Transactions.Info(contextcreateTx, *createTx.ID) if err != nil { panic(err) } // Print the transaction info. fmt.Printf("Transaction info: %+v\n", createTxInfo) }
- Install the dependencies:
go mod tidy
- Run the application:
go run waves.go
# Burn
In your project directory:
- Replace the
waves.go
file code with the following snippet:package main // Necessary imports. import ( "bytes" "context" "encoding/binary" "fmt" "net/http" "time" "github.com/wavesplatform/gowaves/pkg/client" "github.com/wavesplatform/gowaves/pkg/crypto" "github.com/wavesplatform/gowaves/pkg/proto" ) func main() { /* Specify the network: - Mainnet: `proto.MainNetScheme` - Testnet: `proto.TestNetScheme` - Stagenet: `proto.StageNetScheme` */ const network = proto.TestNetScheme nodeClient, err := client.NewClient(client.Options{ /* Specify the link for the same network as mentioned above: - Mainnet: "https://nodes.wavesnodes.com/" - Testnet: "https://nodes-testnet.wavesnodes.com/" - Stagenet: "https://nodes-stagenet.wavesnodes.com/" */ BaseUrl: "https://nodes-testnet.wavesnodes.com/", Client: &http.Client{}, ChainID: network, }) // Print the error if caught. if err != nil { panic(err) } // Set the wallet parameters. const ( accountNumber = 0 // Account number in the wallet. Zero by default. // Specify the seed phrase of your wallet. seedPhrase = "PASTE YOUR SEED PHRASE" ) // Transform the wallet's seed phrase into the required format. accountNumConcatSeedPhrase := bytes.Join([][]byte{ binary.BigEndian.AppendUint32(nil, accountNumber), []byte(seedPhrase), }, nil) // Get the necessary details about the wallet's seed. accountSeed, err := crypto.SecureHash(accountNumConcatSeedPhrase) if err != nil { panic(err) } // Generate the key pair from the wallet's seed phrase. senderPrivateKey, senderPublicKey, err := crypto.GenerateKeyPair(accountSeed.Bytes()) if err != nil { panic(err) } // Current time in milliseconds. currentTime := uint64(time.Now().UnixMilli()) // Define the asset ID to be burned. assetID, err := crypto.NewDigestFromBase58("PASTE AN ASSET ID") if err != nil { panic(err) } // Build a Burn Transaction. createTx := proto.NewUnsignedBurnWithSig( senderPublicKey, // Sender's public key. assetID, // Asset's ID. 100, // Token quantity in the smallest unit. E.g., `100` for 1. currentTime, // Current time. 1000000, // Fee in WAVES in the smallest unit. E.g., `100000000` for 1 token. ) // Sign the transaction with the sender's private key. err = createTx.Sign(network, senderPrivateKey) if err != nil { panic(err) } // Context to cancel the request execution on timeout. contextcreateTx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() // Send the transaction to the node. _, err = nodeClient.Transactions.Broadcast(contextcreateTx, createTx) if err != nil { panic(err) } // Print the message if the transaction has been successfully sent. fmt.Printf("Transaction %q sent successfully\n", createTx.ID.String()) // Set the timeout to ensure the transaction has appeared on the blockchain. time.Sleep(5 * time.Second) // Get the information about the transaction from the node. createTxInfo, _, err := nodeClient.Transactions.Info(contextcreateTx, *createTx.ID) if err != nil { panic(err) } // Print the transaction info. fmt.Printf("Transaction info: %+v\n", createTxInfo) }
- Install the dependencies:
go mod tidy
- Run the application:
go run waves.go
# Transfer
In your project directory:
- Replace the
waves.go
file code with the following snippet:package main // Necessary imports. import ( "bytes" "context" "encoding/binary" "fmt" "net/http" "time" "github.com/wavesplatform/gowaves/pkg/client" "github.com/wavesplatform/gowaves/pkg/crypto" "github.com/wavesplatform/gowaves/pkg/proto" ) func main() { /* Specify the network: - Mainnet: `proto.MainNetScheme` - Testnet: `proto.TestNetScheme` - Stagenet: `proto.StageNetScheme` */ const network = proto.TestNetScheme nodeClient, err := client.NewClient(client.Options{ /* Specify the link for the same network as mentioned above: - Mainnet: "https://nodes.wavesnodes.com/" - Testnet: "https://nodes-testnet.wavesnodes.com/" - Stagenet: "https://nodes-stagenet.wavesnodes.com/" */ BaseUrl: "https://nodes-testnet.wavesnodes.com/", Client: &http.Client{}, ChainID: network, }) // Print the error if caught. if err != nil { panic(err) } // Set the wallet parameters. const ( accountNumber = 0 // Account number in the wallet. Zero by default. // Specify the seed phrase of your wallet. seedPhrase = "PASTE YOUR SEED PHRASE" ) // Transform the wallet's seed phrase into the required format. accountNumConcatSeedPhrase := bytes.Join([][]byte{ binary.BigEndian.AppendUint32(nil, accountNumber), []byte(seedPhrase), }, nil) // Get the necessary details about the wallet's seed. accountSeed, err := crypto.SecureHash(accountNumConcatSeedPhrase) if err != nil { panic(err) } // Generate the key pair from the wallet's seed phrase. senderPrivateKey, senderPublicKey, err := crypto.GenerateKeyPair(accountSeed.Bytes()) if err != nil { panic(err) } // Current time in milliseconds. currentTime := uint64(time.Now().UnixMilli()) // Define the recipient's address. recipientAddr, err := proto.NewAddressFromString("PASTE THE RECIPIENT'S ADDRESS") if err != nil { panic(err) } recipient := proto.NewRecipientFromAddress(recipientAddr) /* Define the asset to transfer: - Use "WAVES" for transactions in the native token, WAVES. - Or enter the asset's ID. */ amountAsset, err := proto.NewOptionalAssetFromString("WAVES") if err != nil { panic(err) } // Specify WAVES as the fee asset. feeAsset, err := proto.NewOptionalAssetFromString("WAVES") if err != nil { panic(err) } // Define attachment. attachment := []byte("PASTE ATTACHMENT MESSAGE") // Build a Transfer Transaction. createTx := proto.NewUnsignedTransferWithSig( senderPublicKey, // Sender's public key. *amountAsset, // Asset's amount. *feeAsset, // Fee's asset. currentTime, // Current time. 200000000, // Amount to transfer in the smallest unit. E.g., `100000000` for 1 token. 100000, // Fee in WAVES in the smallest unit. E.g., `100000000` for 1 token. recipient, // Recipient's address. attachment, // Attachment. ) // Sign the transaction with the sender's private key. err = createTx.Sign(network, senderPrivateKey) if err != nil { panic(err) } // Context to cancel the request execution on timeout. contextcreateTx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() // Send the transaction to the node. _, err = nodeClient.Transactions.Broadcast(contextcreateTx, createTx) if err != nil { panic(err) } // Print the message if the transaction has been successfully sent. fmt.Printf("Transaction %q sent successfully\n", createTx.ID.String()) // Set the timeout to ensure the transaction has appeared on the blockchain. time.Sleep(5 * time.Second) // Get the information about the transaction from the node. createTxInfo, _, err := nodeClient.Transactions.Info(contextcreateTx, *createTx.ID) if err != nil { panic(err) } // Print the transaction info. fmt.Printf("Transaction info: %+v\n", createTxInfo) }
- Install the dependencies:
go mod tidy
- Run the application:
go run waves.go
# Mass Transfer
About Mass Transfer Transaction.
In your project directory:
- Replace the
waves.go
file code with the following snippet:package main // Necessary imports. import ( "bytes" "context" "encoding/binary" "fmt" "net/http" "time" "github.com/wavesplatform/gowaves/pkg/client" "github.com/wavesplatform/gowaves/pkg/crypto" "github.com/wavesplatform/gowaves/pkg/proto" ) func main() { /* Specify the network: - Mainnet: `proto.MainNetScheme` - Testnet: `proto.TestNetScheme` - Stagenet: `proto.StageNetScheme` */ const network = proto.TestNetScheme nodeClient, err := client.NewClient(client.Options{ /* Specify the link for the same network as mentioned above: - Mainnet: "https://nodes.wavesnodes.com/" - Testnet: "https://nodes-testnet.wavesnodes.com/" - Stagenet: "https://nodes-stagenet.wavesnodes.com/" */ BaseUrl: "https://nodes-testnet.wavesnodes.com/", Client: &http.Client{}, ChainID: network, }) // Print the error if caught. if err != nil { panic(err) } // Set the wallet parameters. const ( accountNumber = 0 // Account number in the wallet. Zero by default. // Specify the seed phrase of your wallet. seedPhrase = "PASTE YOUR SEED PHRASE" ) // Transform the wallet's seed phrase into the required format. accountNumConcatSeedPhrase := bytes.Join([][]byte{ binary.BigEndian.AppendUint32(nil, accountNumber), []byte(seedPhrase), }, nil) // Get the necessary details about the wallet's seed. accountSeed, err := crypto.SecureHash(accountNumConcatSeedPhrase) if err != nil { panic(err) } // Generate the key pair from the wallet's seed phrase. senderPrivateKey, senderPublicKey, err := crypto.GenerateKeyPair(accountSeed.Bytes()) if err != nil { panic(err) } // Current time in milliseconds. currentTime := uint64(time.Now().UnixMilli()) // Define the address of the 1st recipient. addr1, err := proto.NewAddressFromString("PASTE THE RECIPIENT'S ADDRESS") if err != nil { panic(err) } // Define the address of the 2nd recipient. addr2, err := proto.NewAddressFromString("PASTE THE RECIPIENT'S ADDRESS") if err != nil { panic(err) } // Define the address of the 3rd recipient. addr3, err := proto.NewAddressFromString("PASTE THE RECIPIENT'S ADDRESS") if err != nil { panic(err) } // Format the recipient addresses. recipient1 := proto.NewRecipientFromAddress(addr1) recipient2 := proto.NewRecipientFromAddress(addr2) recipient3 := proto.NewRecipientFromAddress(addr3) /* Define the asset to transfer: - Use "WAVES" for transactions in the native token, WAVES. - Or enter the asset's ID. */ asset, err := proto.NewOptionalAssetFromString("WAVES") if err != nil { panic(err) } // Define the amounts of the mass transfers to each recipient. transfers := []proto.MassTransferEntry{ {Recipient: recipient1, Amount: 100000}, {Recipient: recipient2, Amount: 100000}, {Recipient: recipient3, Amount: 100000}, } // Define the custom attachment. attachment := []byte("PASTE ATTACHMENT MESSAGE") // Build a MassTransfer transaction. createTx := proto.NewUnsignedMassTransferWithProofs( 1, // Transaction version. senderPublicKey, // Sender's public key. *asset, // Transfer asset. transfers, // List of recipients and amounts. 300000, // Fee in WAVES in the smallest unit. E.g., `100000000` for 1 token. currentTime, // Current time. attachment, // Attachment message. ) // Sign the transaction with the sender's private key. err = createTx.Sign(network, senderPrivateKey) if err != nil { panic(err) } // Context to cancel the request execution on timeout. contextcreateTx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() // Send the transaction to the node. _, err = nodeClient.Transactions.Broadcast(contextcreateTx, createTx) if err != nil { panic(err) } // Print the message if the transaction has been successfully sent. fmt.Printf("Transaction %q sent successfully\n", createTx.ID.String()) // Set the timeout to ensure the transaction has appeared on the blockchain. time.Sleep(5 * time.Second) // Get the information about the transaction from the node. createTxInfo, _, err := nodeClient.Transactions.Info(contextcreateTx, *createTx.ID) if err != nil { panic(err) } // Print the transaction info. fmt.Printf("Transaction info: %+v\n", createTxInfo) }
- Install the dependencies:
go mod tidy
- Run the application:
go run waves.go
# Exchange
In your project directory:
- Replace the
waves.go
file code with the following snippet:package main // Necessary imports. import ( "bytes" "context" "encoding/binary" "fmt" "net/http" "time" "github.com/wavesplatform/gowaves/pkg/client" "github.com/wavesplatform/gowaves/pkg/crypto" "github.com/wavesplatform/gowaves/pkg/proto" ) func main() { /* Specify the network: - Mainnet: `proto.MainNetScheme` - Testnet: `proto.TestNetScheme` - Stagenet: `proto.StageNetScheme` */ const network = proto.TestNetScheme nodeClient, err := client.NewClient(client.Options{ /* Specify the link for the same network as mentioned above: - Mainnet: "https://nodes.wavesnodes.com/" - Testnet: "https://nodes-testnet.wavesnodes.com/" - Stagenet: "https://nodes-stagenet.wavesnodes.com/" */ BaseUrl: "https://nodes-testnet.wavesnodes.com/", Client: &http.Client{}, ChainID: network, }) // Print the error if caught. if err != nil { panic(err) } // Set the wallet parameters. const ( accountNumber = 0 // Account number in the wallet. Zero by default. // Specify the seed phrase of your wallet. seedPhrase = "PASTE YOUR SEED PHRASE" ) // Transform the wallet's seed phrase into the required format. accountNumConcatSeedPhrase := bytes.Join([][]byte{ binary.BigEndian.AppendUint32(nil, accountNumber), []byte(seedPhrase), }, nil) // Get the necessary details about the wallet's seed. accountSeed, err := crypto.SecureHash(accountNumConcatSeedPhrase) if err != nil { panic(err) } // Generate the key pair from the wallet's seed phrase. senderPrivateKey, senderPublicKey, err := crypto.GenerateKeyPair(accountSeed.Bytes()) if err != nil { panic(err) } // Current time in milliseconds. currentTime := uint64(time.Now().UnixMilli()) // Define the asset ID to be exchanged. amountAsset, err := proto.NewOptionalAssetFromString("PASTE THE ASSET ID") if err != nil { panic(err) } // Define price asset. priceAsset, err := proto.NewOptionalAssetFromString("") if err != nil { panic(err) } // Order expiration time. expiration := currentTime + 100*1000 // Generate the buy order. buyOrder := proto.NewUnsignedOrderV1( senderPublicKey, // Sender’s public key. senderPublicKey, // Matcher’s public key (same here for simplicity). *amountAsset, // Asset to buy. *priceAsset, // Asset used to pay: WAVES. proto.Buy, // Order type: Buy. 100, // Price in `priceAsset` per `amountAsset`, in smallest units. 100, // Total amount to buy, in smallest units. currentTime, // Timestamp when the order was created. expiration, // Order expiration time. 1000000, // Fee in WAVES in the smallest unit. E.g., `100000000` for 1 token. ) err = buyOrder.Sign(proto.TestNetScheme, senderPrivateKey) if err != nil { panic(err) } // Generate the sell order. sellOrder := proto.NewUnsignedOrderV1( senderPublicKey, // Seller's public key. senderPublicKey, // Matcher's public key (same here for simplicity). *amountAsset, // Asset to sell. *priceAsset, // Asset to receive. proto.Sell, // Order type: Sell. 100, // Price. Must match the buy order. 100, // Amount to sell. currentTime, // Creation time. expiration, // Order expiration time. 1000000, // Fee in WAVES in the smallest unit. E.g., `100000000` for 1 token. ) err = sellOrder.Sign(proto.TestNetScheme, senderPrivateKey) if err != nil { panic(err) } // Define the exchange transaction details. price := sellOrder.Price // Must match both orders' price. amount := uint64(456) // Amount to exchange. buyMatcherFee := uint64(789) // Fee paid by buyer (partially). sellMatcherFee := uint64(987) // Fee paid by seller (partially). fee := uint64(3000000) // Fee paid to the network to broadcast the exchange. // Build an Exchange Transaction. createTx := proto.NewUnsignedExchangeWithSig( buyOrder, // Buy order. sellOrder, // Sell order. price, // Agreed price. amount, // Amount of asset exchanged. buyMatcherFee, // Buyer's matcher fee. sellMatcherFee, // Seller's matcher fee. fee, // Transaction fee. currentTime, // Timestamp. ) // Sign the transaction with the sender's private key. err = createTx.Sign(proto.TestNetScheme, senderPrivateKey) if err != nil { panic(err) } // Context to cancel the request execution on timeout. ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() // Send the transaction to the node. _, err = nodeClient.Transactions.Broadcast(ctx, createTx) if err != nil { panic(err) } // Print the message if the transaction has been successfully sent. fmt.Printf("Transaction %q sent successfully\n", createTx.ID.String()) // Set the timeout to ensure the transaction has appeared on the blockchain. time.Sleep(5 * time.Second) // Get the information about the transaction from the node. createTxInfo, _, err := nodeClient.Transactions.Info(ctx, *createTx.ID) if err != nil { panic(err) } // Print the transaction info. fmt.Printf("Transaction info: %+v\n", createTxInfo) }
- Install the dependencies:
go mod tidy
- Run the application:
go run waves.go
# Lease
In your project directory:
- Replace the
waves.go
file code with the following snippet:package main // Necessary imports. import ( "bytes" "context" "encoding/binary" "fmt" "net/http" "time" "github.com/wavesplatform/gowaves/pkg/client" "github.com/wavesplatform/gowaves/pkg/crypto" "github.com/wavesplatform/gowaves/pkg/proto" ) func main() { /* Specify the network: - Mainnet: `proto.MainNetScheme` - Testnet: `proto.TestNetScheme` - Stagenet: `proto.StageNetScheme` */ const network = proto.TestNetScheme nodeClient, err := client.NewClient(client.Options{ /* Specify the link for the same network as mentioned above: - Mainnet: "https://nodes.wavesnodes.com/" - Testnet: "https://nodes-testnet.wavesnodes.com/" - Stagenet: "https://nodes-stagenet.wavesnodes.com/" */ BaseUrl: "https://nodes-testnet.wavesnodes.com/", Client: &http.Client{}, ChainID: network, }) // Print the error if caught. if err != nil { panic(err) } // Set the wallet parameters. const ( accountNumber = 0 // Account number in the wallet. Zero by default. // Specify the seed phrase of your wallet. seedPhrase = "PASTE YOUR SEED PHRASE" ) // Transform the wallet's seed phrase into the required format. accountNumConcatSeedPhrase := bytes.Join([][]byte{ binary.BigEndian.AppendUint32(nil, accountNumber), []byte(seedPhrase), }, nil) // Get the necessary details about the wallet's seed. accountSeed, err := crypto.SecureHash(accountNumConcatSeedPhrase) if err != nil { panic(err) } // Generate the key pair from the wallet's seed phrase. senderPrivateKey, senderPublicKey, err := crypto.GenerateKeyPair(accountSeed.Bytes()) if err != nil { panic(err) } // Current time in milliseconds. currentTime := uint64(time.Now().UnixMilli()) // Define recipient address. recipientAddr, err := proto.NewAddressFromString("PASTE THE RECIPIENT'S ADDRESS") if err != nil { panic(err) } recipient := proto.NewRecipientFromAddress(recipientAddr) // Define the lease amount. leaseAmount := uint64(1234567890) // Define the transaction fee. leaseFee := uint64(100000) // Recommended minimum fee for the Lease transaction. // Build the Lease Transaction. createTx := proto.NewUnsignedLeaseWithSig( senderPublicKey, // Sender's public key. recipient, // Recipient. leaseAmount, // Lease amount. leaseFee, // Lease fee. currentTime, // Current time. ) // Sign the transaction with the sender's private key. err = createTx.Sign(network, senderPrivateKey) if err != nil { panic(err) } // Context to cancel the request execution on timeout. contextcreateTx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() // Send the transaction to the node. _, err = nodeClient.Transactions.Broadcast(contextcreateTx, createTx) if err != nil { panic(err) } // Print the message if the transaction has been successfully sent. fmt.Printf("Transaction %q sent successfully\n", createTx.ID.String()) // Set the timeout to ensure the transaction has appeared on the blockchain. time.Sleep(5 * time.Second) // Get the information about the transaction from the node. createTxInfo, _, err := nodeClient.Transactions.Info(contextcreateTx, *createTx.ID) if err != nil { panic(err) } // Print the transaction info. fmt.Printf("Transaction info: %+v\n", createTxInfo) }
- Install the dependencies:
go mod tidy
- Run the application:
go run waves.go
# Lease Cancel
About Lease Cancel Transaction.
In your project directory:
- Replace the
waves.go
file code with the following snippet:package main // Necessary imports. import ( "bytes" "context" "encoding/binary" "fmt" "net/http" "time" "github.com/wavesplatform/gowaves/pkg/client" "github.com/wavesplatform/gowaves/pkg/crypto" "github.com/wavesplatform/gowaves/pkg/proto" ) func main() { /* Specify the network: - Mainnet: `proto.MainNetScheme` - Testnet: `proto.TestNetScheme` - Stagenet: `proto.StageNetScheme` */ const network = proto.TestNetScheme nodeClient, err := client.NewClient(client.Options{ /* Specify the link for the same network as mentioned above: - Mainnet: "https://nodes.wavesnodes.com/" - Testnet: "https://nodes-testnet.wavesnodes.com/" - Stagenet: "https://nodes-stagenet.wavesnodes.com/" */ BaseUrl: "https://nodes-testnet.wavesnodes.com/", Client: &http.Client{}, ChainID: network, }) // Print the error if caught. if err != nil { panic(err) } // Set the wallet parameters. const ( accountNumber = 0 // Account number in the wallet. Zero by default. // Specify the seed phrase of your wallet. seedPhrase = "PASTE YOUR SEED PHRASE" ) // Transform the wallet's seed phrase into the required format. accountNumConcatSeedPhrase := bytes.Join([][]byte{ binary.BigEndian.AppendUint32(nil, accountNumber), []byte(seedPhrase), }, nil) // Get the necessary details about the wallet's seed. accountSeed, err := crypto.SecureHash(accountNumConcatSeedPhrase) if err != nil { panic(err) } // Generate the key pair from the wallet's seed phrase. senderPrivateKey, senderPublicKey, err := crypto.GenerateKeyPair(accountSeed.Bytes()) if err != nil { panic(err) } // Current time in milliseconds. currentTime := uint64(time.Now().UnixMilli()) // Define the ID of your Lease transaction to cancel. leaseID, err := crypto.NewDigestFromBase58("PASTE YOUR LEASE TRANSACTION'S ID") if err != nil { panic(err) } // Specify the transaction fee. cancelFee := uint64(100000) // Minimum fee for lease cancel. // Build the Lease Cancel Transaction. createTx := proto.NewUnsignedLeaseCancelWithSig( senderPublicKey, // Sender's public key. leaseID, // Lease tranasaction's ID. cancelFee, // Cancel fee. currentTime, // Current time. ) // Sign the transaction with the sender's private key. err = createTx.Sign(network, senderPrivateKey) if err != nil { panic(err) } // Context to cancel the request execution on timeout. contextcreateTx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() // Send the transaction to the node. _, err = nodeClient.Transactions.Broadcast(contextcreateTx, createTx) if err != nil { panic(err) } // Print the message if the transaction has been successfully sent. fmt.Printf("Transaction %q sent successfully\n", createTx.ID.String()) // Set the timeout to ensure the transaction has appeared on the blockchain. time.Sleep(5 * time.Second) // Get the information about the transaction from the node. createTxInfo, _, err := nodeClient.Transactions.Info(contextcreateTx, *createTx.ID) if err != nil { panic(err) } // Print the transaction info. fmt.Printf("Transaction info: %+v\n", createTxInfo) }
- Install the dependencies:
go mod tidy
- Run the application:
go run waves.go
# Create Alias
About Create Alias Transaction.
In your project directory:
- Replace the
waves.go
file code with the following snippet:package main // Necessary imports. import ( "bytes" "context" "encoding/binary" "fmt" "net/http" "strconv" "time" "github.com/wavesplatform/gowaves/pkg/client" "github.com/wavesplatform/gowaves/pkg/crypto" "github.com/wavesplatform/gowaves/pkg/proto" ) func main() { /* Specify the network: - Mainnet: `proto.MainNetScheme` - Testnet: `proto.TestNetScheme` - Stagenet: `proto.StageNetScheme` */ const network = proto.TestNetScheme nodeClient, err := client.NewClient(client.Options{ /* Specify the link for the same network as mentioned above: - Mainnet: "https://nodes.wavesnodes.com/" - Testnet: "https://nodes-testnet.wavesnodes.com/" - Stagenet: "https://nodes-stagenet.wavesnodes.com/" */ BaseUrl: "https://nodes-testnet.wavesnodes.com/", Client: &http.Client{}, ChainID: network, }) // Print the error if caught. if err != nil { panic(err) } // Set the wallet parameters. const ( accountNumber = 0 // Account number in the wallet. Zero by default. // Specify the seed phrase of your wallet. seedPhrase = "PASTE YOUR SEED PHRASE" ) // Transform the wallet's seed phrase into the required format. accountNumConcatSeedPhrase := bytes.Join([][]byte{ binary.BigEndian.AppendUint32(nil, accountNumber), []byte(seedPhrase), }, nil) // Get the necessary details about the wallet's seed. accountSeed, err := crypto.SecureHash(accountNumConcatSeedPhrase) if err != nil { panic(err) } // Generate the key pair from the wallet's seed phrase. senderPrivateKey, senderPublicKey, err := crypto.GenerateKeyPair(accountSeed.Bytes()) if err != nil { panic(err) } // Current time in milliseconds. currentTime := uint64(time.Now().UnixMilli()) // Create alias, using the system's current time. alias := proto.NewAlias(network, strconv.FormatUint(currentTime, 10)) // Build a Create Alias Transaction. createTx := proto.NewUnsignedCreateAliasWithProofs( 3, // Transaction version. senderPublicKey, // Sender's public key. *alias, // Alias. 100000, // Transaction fee in WAVES in the smallest unit. E.g., `100000000` for 1 token. /* NOTE: The bigger the fee value is, the faster the transaction will be included in the blockchain. Read more about transaction fees: https://docs.waves.tech/en/blockchain/transaction/transaction-fee Read more about transaction version: https://docs.waves.tech/en/blockchain/binary-format/transaction-binary-format */ currentTime) // Current time in milliseconds. // Sign the transaction with the sender's private key. err = createTx.Sign(network, senderPrivateKey) if err != nil { panic(err) } // Context to cancel the request execution on timeout. contextcreateTx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() // Send the transaction to the node. _, err = nodeClient.Transactions.Broadcast(contextcreateTx, createTx) if err != nil { panic(err) } // Print the message if the transaction has been successfully sent. fmt.Printf("Transaction %q sent successfully\n", createTx.ID.String()) // Set the timeout to ensure the transaction has appeared on the blockchain. time.Sleep(5 * time.Second) // Get the information about the transaction from the node. createTxInfo, _, err := nodeClient.Transactions.Info(contextcreateTx, *createTx.ID) if err != nil { panic(err) } // Print the transaction info. fmt.Printf("Transaction info: %+v\n", createTxInfo) }
- Install the dependencies:
go mod tidy
- Run the application:
go run waves.go
# Data
In your project directory:
- Replace the
waves.go
file code with the following snippet:package main // Necessary imports. import ( "bytes" "context" "encoding/binary" "fmt" "net/http" "time" "github.com/mr-tron/base58/base58" "github.com/wavesplatform/gowaves/pkg/client" "github.com/wavesplatform/gowaves/pkg/crypto" "github.com/wavesplatform/gowaves/pkg/proto" ) func main() { /* Specify the network: - Mainnet: `proto.MainNetScheme` - Testnet: `proto.TestNetScheme` - Stagenet: `proto.StageNetScheme` */ const network = proto.TestNetScheme nodeClient, err := client.NewClient(client.Options{ /* Specify the link for the same network as mentioned above: - Mainnet: "https://nodes.wavesnodes.com/" - Testnet: "https://nodes-testnet.wavesnodes.com/" - Stagenet: "https://nodes-stagenet.wavesnodes.com/" */ BaseUrl: "https://nodes-testnet.wavesnodes.com/", Client: &http.Client{}, ChainID: network, }) // Print the error if caught. if err != nil { panic(err) } // Set the wallet parameters. const ( accountNumber = 0 // Account number in the wallet. Zero by default. // Specify the seed phrase of your wallet. seedPhrase = "PASTE YOUR SEED PHRASE" ) // Transform the wallet's seed phrase into the required format. accountNumConcatSeedPhrase := bytes.Join([][]byte{ binary.BigEndian.AppendUint32(nil, accountNumber), []byte(seedPhrase), }, nil) // Get the necessary details about the wallet's seed. accountSeed, err := crypto.SecureHash(accountNumConcatSeedPhrase) if err != nil { panic(err) } // Generate the key pair from the wallet's seed phrase. senderPrivateKey, senderPublicKey, err := crypto.GenerateKeyPair(accountSeed.Bytes()) if err != nil { panic(err) } // Current time in milliseconds. currentTime := uint64(time.Now().UnixMilli()) // Build a Data Transaction. createTx := proto.NewUnsignedDataWithProofs( 1, // Transaction version. senderPublicKey, // Sender's public key. 100000, // Fee in WAVES in the smallest unit. E.g., `100000000` for 1 token. currentTime, // Current time. ) // Decode the binary value required for the transaction. decoded, err := base58.Decode("4JMP6WwpP78EVYZzG9CKQKDUTPUdvMCYGKVNn4G3VdHmW5mZKNXbvHvuvA8Nj6p39k8htY9VkM6uSf5ombFzETJq") // Example value. if err != nil { panic(err) } // Append data entries. entries := []proto.DataEntry{ &proto.IntegerDataEntry{Key: "int-val", Value: 1234567890}, &proto.BooleanDataEntry{Key: "bool-val", Value: true}, &proto.BinaryDataEntry{Key: "bin-val", Value: decoded }, &proto.StringDataEntry{Key: "string-val", Value: "some string"}, } // Process the given entries. for _, entry := range entries { err := createTx.AppendEntry(entry) if err != nil { panic(err) } } // Sign the transaction with the sender's private key. err = createTx.Sign(network, senderPrivateKey) if err != nil { panic(err) } // Context to cancel the request execution on timeout. contextcreateTx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() // Send the transaction to the node. _, err = nodeClient.Transactions.Broadcast(contextcreateTx, createTx) if err != nil { panic(err) } // Print the message if the transaction has been successfully sent. fmt.Printf("Transaction %q sent successfully\n", createTx.ID.String()) // Set the timeout to ensure the transaction has appeared on the blockchain. time.Sleep(5 * time.Second) // Get the information about the transaction from the node. createTxInfo, _, err := nodeClient.Transactions.Info(contextcreateTx, *createTx.ID) if err != nil { panic(err) } // Print the transaction info. fmt.Printf("Transaction info: %+v\n", createTxInfo) }
- Install the dependencies:
go mod tidy
- Run the application:
go run waves.go
# Set Script
In your project directory:
- Replace the
waves.go
file code with the following snippet:package main // Necessary imports. import ( "bytes" "context" "encoding/binary" "fmt" "net/http" "time" "github.com/wavesplatform/gowaves/pkg/client" "github.com/wavesplatform/gowaves/pkg/crypto" "github.com/wavesplatform/gowaves/pkg/proto" "github.com/wavesplatform/gowaves/pkg/ride/compiler" ) func main() { /* Specify the network: - Mainnet: `proto.MainNetScheme` - Testnet: `proto.TestNetScheme` - Stagenet: `proto.StageNetScheme` */ const network = proto.TestNetScheme nodeClient, err := client.NewClient(client.Options{ /* Specify the link for the same network as mentioned above: - Mainnet: "https://nodes.wavesnodes.com/" - Testnet: "https://nodes-testnet.wavesnodes.com/" - Stagenet: "https://nodes-stagenet.wavesnodes.com/" */ BaseUrl: "https://nodes-testnet.wavesnodes.com/", Client: &http.Client{}, ChainID: network, }) // Print the error if caught. if err != nil { panic(err) } // Set the wallet parameters. const ( accountNumber = 0 // Account number in the wallet. Zero by default. // Specify the seed phrase of your wallet. seedPhrase = "PASTE YOUR SEED PHRASE" ) // Transform the wallet's seed phrase into the required format. accountNumConcatSeedPhrase := bytes.Join([][]byte{ binary.BigEndian.AppendUint32(nil, accountNumber), []byte(seedPhrase), }, nil) // Get the necessary details about the wallet's seed. accountSeed, err := crypto.SecureHash(accountNumConcatSeedPhrase) if err != nil { panic(err) } // Generate the key pair from the wallet's seed phrase. senderPrivateKey, senderPublicKey, err := crypto.GenerateKeyPair(accountSeed.Bytes()) if err != nil { panic(err) } // Current time in milliseconds. currentTime := uint64(time.Now().UnixMilli()) // Enter your account's raw Ride script. rideScript := ` {-# STDLIB_VERSION 8 #-} {-# CONTENT_TYPE DAPP #-} {-# SCRIPT_TYPE ACCOUNT #-} @Callable(i) func checkStorageUntouchedByAlias(accountAlias: String) = { let alias = Alias(accountAlias) let res = if isDataStorageUntouched(alias) then { unit } else { throw("Data storage is not untouched by alias") } ([], res) } ` // Compile the Ride script. compiledScript, errList := compiler.Compile(rideScript, true, true) // `true` for DApp and `true` for the `ACCOUNT` type. if errList != nil && len(errList) > 0 { // Check whether there were any errors during compilation. panic(fmt.Sprintf("Error compiling script: %v", errList)) } // Build a Set Script Transaction. setScriptFee := uint64(1400000) createTx := proto.NewUnsignedSetScriptWithProofs( 1, // Transaction version. senderPublicKey, // Sender's public key. compiledScript, // Compiled ride script or `nil` if you want to remove the account script. setScriptFee, // The transaction fee. currentTime, // Current time. ) // Sign the transaction with the sender's private key. err = createTx.Sign(network, senderPrivateKey) if err != nil { panic(err) } // Context to cancel the request execution on timeout. contextcreateTx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() // Send the transaction to the node. _, err = nodeClient.Transactions.Broadcast(contextcreateTx, createTx) if err != nil { panic(err) } // Print the message if the transaction has been successfully sent. fmt.Printf("Transaction %q sent successfully\n", createTx.ID.String()) // Set the timeout to ensure the transaction has appeared on the blockchain. time.Sleep(5 * time.Second) // Get the information about the transaction from the node. createTxInfo, _, err := nodeClient.Transactions.Info(contextcreateTx, *createTx.ID) if err != nil { panic(err) } // Print the transaction info. fmt.Printf("Transaction info: %+v\n", createTxInfo) }
- Install the dependencies:
go mod tidy
- Run the application:
go run waves.go
# Set Asset Script
About Set Asset Script Transaction.
NOTE: You can set an asset script only on those asset that were issued with a ride script attached.
In your project directory:
- Replace the
waves.go
file code with the following snippet:package main // Necessary imports. import ( "bytes" "context" "encoding/binary" "fmt" "net/http" "time" "github.com/wavesplatform/gowaves/pkg/client" "github.com/wavesplatform/gowaves/pkg/crypto" "github.com/wavesplatform/gowaves/pkg/proto" "github.com/wavesplatform/gowaves/pkg/ride/compiler" ) func main() { /* Specify the network: - Mainnet: `proto.MainNetScheme` - Testnet: `proto.TestNetScheme` - Stagenet: `proto.StageNetScheme` */ const network = proto.TestNetScheme nodeClient, err := client.NewClient(client.Options{ /* Specify the link for the same network as mentioned above: - Mainnet: "https://nodes.wavesnodes.com/" - Testnet: "https://nodes-testnet.wavesnodes.com/" - Stagenet: "https://nodes-stagenet.wavesnodes.com/" */ BaseUrl: "https://nodes-testnet.wavesnodes.com/", Client: &http.Client{}, ChainID: network, }) // Print the error if caught. if err != nil { panic(err) } // Set the wallet parameters. const ( accountNumber = 0 // Account number in the wallet. Zero by default. // Specify the seed phrase of your wallet. seedPhrase = "PASTE YOUR SEED PHRASE" ) // Transform the wallet's seed phrase into the required format. accountNumConcatSeedPhrase := bytes.Join([][]byte{ binary.BigEndian.AppendUint32(nil, accountNumber), []byte(seedPhrase), }, nil) // Get the necessary details about the wallet's seed. accountSeed, err := crypto.SecureHash(accountNumConcatSeedPhrase) if err != nil { panic(err) } // Generate the key pair from the wallet's seed phrase. senderPrivateKey, senderPublicKey, err := crypto.GenerateKeyPair(accountSeed.Bytes()) if err != nil { panic(err) } // Current time in milliseconds. currentTime := uint64(time.Now().UnixMilli()) // Define the asset ID. assetID, err := crypto.NewDigestFromBase58("PASTE YOUR ASSET'S ID") if err != nil { panic(err) } // Enter an asset script in Ride. rideScript := ` {-# STDLIB_VERSION 8 #-} {-# CONTENT_TYPE EXPRESSION #-} {-# SCRIPT_TYPE ASSET #-} true ` // Compile the ride script. compiledScript, errList := compiler.Compile(rideScript, false, true) if errList != nil && len(errList) > 0 { panic(fmt.Sprintf("Error compiling script: %v", errList)) } // Build a Set Asset Script Transaction. createTx := proto.NewUnsignedSetAssetScriptWithProofs( 1, // Transaction version. senderPublicKey, // Sender's public key. assetID, // Asset's ID. compiledScript, // Compiled Ride script. 99600000, // Fee in WAVES in the smallest unit. E.g., `100000000` for 1 token. currentTime, // Current time. ) // Sign the transaction with the sender's private key. err = createTx.Sign(network, senderPrivateKey) if err != nil { panic(err) } // Context to cancel the request execution on timeout. contextcreateTx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() // Send the transaction to the node. _, err = nodeClient.Transactions.Broadcast(contextcreateTx, createTx) if err != nil { panic(err) } // Print the message if the transaction has been successfully sent. fmt.Printf("Transaction %q sent successfully\n", createTx.ID.String()) // Set the timeout to ensure the transaction has appeared on the blockchain. time.Sleep(5 * time.Second) // Get the information about the transaction from the node. createTxInfo, _, err := nodeClient.Transactions.Info(contextcreateTx, *createTx.ID) if err != nil { panic(err) } // Print the transaction info. fmt.Printf("Transaction info: %+v\n", createTxInfo) }
- Install the dependencies:
go mod tidy
- Run the application:
go run waves.go
# Update Asset Info
About Update Asset Info Transaction.
In your project directory:
- Replace the
waves.go
file code with the following snippet:package main // Necessary imports. import ( "bytes" "context" "encoding/binary" "fmt" "net/http" "time" "github.com/wavesplatform/gowaves/pkg/client" "github.com/wavesplatform/gowaves/pkg/crypto" "github.com/wavesplatform/gowaves/pkg/proto" ) func main() { /* Specify the network: - Mainnet: `proto.MainNetScheme` - Testnet: `proto.TestNetScheme` - Stagenet: `proto.StageNetScheme` */ const network = proto.TestNetScheme nodeClient, err := client.NewClient(client.Options{ /* Specify the link for the same network as mentioned above: - Mainnet: "https://nodes.wavesnodes.com/" - Testnet: "https://nodes-testnet.wavesnodes.com/" - Stagenet: "https://nodes-stagenet.wavesnodes.com/" */ BaseUrl: "https://nodes-testnet.wavesnodes.com/", Client: &http.Client{}, ChainID: network, }) // Print the error if caught. if err != nil { panic(err) } // Set the wallet parameters. const ( accountNumber = 0 // Account number in the wallet. Zero by default. // Specify the seed phrase of your wallet. seedPhrase = "PASTE YOUR SEED PHRASE" ) // Transform the wallet's seed phrase into the required format. accountNumConcatSeedPhrase := bytes.Join([][]byte{ binary.BigEndian.AppendUint32(nil, accountNumber), []byte(seedPhrase), }, nil) // Get the necessary details about the wallet's seed. accountSeed, err := crypto.SecureHash(accountNumConcatSeedPhrase) if err != nil { panic(err) } // Generate the key pair from the wallet's seed phrase. senderPrivateKey, senderPublicKey, err := crypto.GenerateKeyPair(accountSeed.Bytes()) if err != nil { panic(err) } // Current time in milliseconds. currentTime := uint64(time.Now().UnixMilli()) // Define a custom asset ID. assetID, err := crypto.NewDigestFromBase58("PASTE AN ASSET ID") if err != nil { panic(err) } // Define optional fee asset. Use `WAVES` or a custom asset ID. feeAsset, err := proto.NewOptionalAssetFromString("WAVES") if err != nil { panic(err) } // Build an Update Asset Info Transaction. createTx := proto.NewUnsignedUpdateAssetInfoWithProofs( 1, // Transaction version. assetID, // Asset ID. senderPublicKey, // Sender's public key. "UpdatedName", // New asset name. "UpdatedDescription", // New asset description. currentTime, // Timestamp. *feeAsset, // Fee asset. 100000, // Fee amount. ) // Sign the transaction with the sender's private key. err = createTx.Sign(network, senderPrivateKey) if err != nil { panic(err) } // Context to cancel the request execution on timeout. contextcreateTx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() // Send the transaction to the node. _, err = nodeClient.Transactions.Broadcast(contextcreateTx, createTx) if err != nil { panic(err) } // Print the message if the transaction has been successfully sent. fmt.Printf("Transaction %q sent successfully\n", createTx.ID.String()) // Set the timeout to ensure the transaction has appeared on the blockchain. time.Sleep(5 * time.Second) // Get the information about the transaction from the node. createTxInfo, _, err := nodeClient.Transactions.Info(contextcreateTx, *createTx.ID) if err != nil { panic(err) } // Print the transaction info. fmt.Printf("Transaction info: %+v\n", createTxInfo) }
- Install the dependencies:
go mod tidy
- Run the application:
go run waves.go
# Invoke Script
About Invoke Script Transaction.
In your project directory:
- Replace the
waves.go
file code with the following snippet:package main // Necessary imports. import ( "bytes" "context" "encoding/binary" "encoding/json" "fmt" "net/http" "time" "github.com/wavesplatform/gowaves/pkg/client" "github.com/wavesplatform/gowaves/pkg/crypto" "github.com/wavesplatform/gowaves/pkg/proto" ) func main() { /* Specify the network: - Mainnet: `proto.MainNetScheme` - Testnet: `proto.TestNetScheme` - Stagenet: `proto.StageNetScheme` */ const network = proto.TestNetScheme nodeClient, err := client.NewClient(client.Options{ /* Specify the link for the same network as mentioned above: - Mainnet: "https://nodes.wavesnodes.com/" - Testnet: "https://nodes-testnet.wavesnodes.com/" - Stagenet: "https://nodes-stagenet.wavesnodes.com/" */ BaseUrl: "https://nodes-testnet.wavesnodes.com/", Client: &http.Client{}, ChainID: network, }) // Print the error if caught. if err != nil { panic(err) } // Set the wallet parameters. const ( accountNumber = 0 // Account number in the wallet. Zero by default. // Specify the seed phrase of your wallet. seedPhrase = "PASTE YOUR SEED PHRASE" ) // Transform the wallet's seed phrase into the required format. accountNumConcatSeedPhrase := bytes.Join([][]byte{ binary.BigEndian.AppendUint32(nil, accountNumber), []byte(seedPhrase), }, nil) // Get the necessary details about the wallet's seed. accountSeed, err := crypto.SecureHash(accountNumConcatSeedPhrase) if err != nil { panic(err) } // Generate the key pair from the wallet's seed phrase. senderPrivateKey, senderPublicKey, err := crypto.GenerateKeyPair(accountSeed.Bytes()) if err != nil { panic(err) } // Current time in milliseconds. currentTime := uint64(time.Now().UnixMilli()) // Insert dApp address. address := "INSERT DAPP ADDRESS" // Specify script invocation parameters. functionCallJSON := `{"function":"bar","args":[{"type":"boolean","value":true}]}` // Specify payment details. paymentsJSON := `[{"amount":67890,"assetId":null}]` // Insert the fee asset ID. feeAssetID := "INSERT FEE ASSET ID" fee := uint64(1000) // Fee amount. // Format the dApp address. recipientAddr, err := proto.NewAddressFromString(address) if err != nil { panic(err) } recipient := proto.NewRecipientFromAddress(recipientAddr) // Parse the function call. var fc proto.FunctionCall err = json.Unmarshal([]byte(functionCallJSON), &fc) if err != nil { panic(err) } // Parse the attached payments. var sps proto.ScriptPayments err = json.Unmarshal([]byte(paymentsJSON), &sps) if err != nil { panic(err) } // Parse the fee asset. feeAsset, err := proto.NewOptionalAssetFromString(feeAssetID) if err != nil { panic(err) } // Build an Invoke Script transaction. var tx *proto.InvokeScriptWithProofs tx = proto.NewUnsignedInvokeScriptWithProofs( 1, // Transaction version. senderPublicKey, // Sender's public key. recipient, // dApp address. fc, // Parsed function call. sps, // Parsed attachment payments. *feeAsset, // Fee asset. fee, // Fee amount. currentTime // Current time. ) // Sign the transaction with the sender's private key. err = tx.Sign(network, senderPrivateKey) if err != nil { panic(err) } // Context to cancel the request execution on timeout. contextCreateTx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() // Send the transaction to the node. _, err = nodeClient.Transactions.Broadcast(contextCreateTx, tx) if err != nil { panic(err) } // Print the message if the transaction has been successfully sent. fmt.Printf("Transaction %q sent successfully\n", tx.ID.String()) // Set the timeout to ensure the transaction has appeared on the blockchain. time.Sleep(5 * time.Second) // Get the information about the transaction from the node. txInfo, _, err := nodeClient.Transactions.Info(contextCreateTx, *tx.ID) if err != nil { panic(err) } // Print the transaction info. fmt.Printf("Transaction info: %+v\n", txInfo) }
- Install the dependencies:
go mod tidy
- Run the application:
go run waves.go
# Sponsor Fee
About Sponsor Fee Transaction.
In your project directory:
- Replace the
waves.go
file code with the following snippet:package main // Necessary imports. import ( "bytes" "context" "encoding/binary" "fmt" "net/http" "time" "github.com/wavesplatform/gowaves/pkg/client" "github.com/wavesplatform/gowaves/pkg/crypto" "github.com/wavesplatform/gowaves/pkg/proto" ) func main() { /* Specify the network: - Mainnet: `proto.MainNetScheme` - Testnet: `proto.TestNetScheme` - Stagenet: `proto.StageNetScheme` */ const network = proto.TestNetScheme nodeClient, err := client.NewClient(client.Options{ /* Specify the link for the same network as mentioned above: - Mainnet: "https://nodes.wavesnodes.com/" - Testnet: "https://nodes-testnet.wavesnodes.com/" - Stagenet: "https://nodes-stagenet.wavesnodes.com/" */ BaseUrl: "https://nodes-testnet.wavesnodes.com/", Client: &http.Client{}, ChainID: network, }) // Print the error if caught. if err != nil { panic(err) } // Set the wallet parameters. const ( accountNumber = 0 // Account number in the wallet. Zero by default. // Specify the seed phrase of your wallet. seedPhrase = "PASTE YOUR SEED PHRASE" ) // Transform the wallet's seed phrase into the required format. accountNumConcatSeedPhrase := bytes.Join([][]byte{ binary.BigEndian.AppendUint32(nil, accountNumber), []byte(seedPhrase), }, nil) // Get the necessary details about the wallet's seed. accountSeed, err := crypto.SecureHash(accountNumConcatSeedPhrase) if err != nil { panic(err) } // Generate the key pair from the wallet's seed phrase. senderPrivateKey, senderPublicKey, err := crypto.GenerateKeyPair(accountSeed.Bytes()) if err != nil { panic(err) } // Current time in milliseconds. currentTime := uint64(time.Now().UnixMilli()) // Define the ID of the sponsor asset. assetID := "PASSTE SPONSOR ASSET'S ID" assetDigest, _ := crypto.NewDigestFromBase58(assetID) // Build a Sponsorship Transaction. tx := proto.NewUnsignedSponsorshipWithProofs( 1, // Transaction version. senderPublicKey, // Sender's public key. assetDigest, // Transaction asset. 100, // Fee for sponsoring the asset. 1234567890, // Network transaction fee in the smallest unit. E.g., `100000000` for 1 token. currentTime // Current time. ) // Sign the transaction with the sender's private key. err = tx.Sign(network, senderPrivateKey) if err != nil { panic(err) } // Context to cancel the request execution on timeout. contextCreateTx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() // Send the transaction to the node. _, err = nodeClient.Transactions.Broadcast(contextCreateTx, tx) if err != nil { panic(err) } // Print the message if the transaction has been successfully sent. fmt.Printf("Transaction %q sent successfully\n", tx.ID.String()) // Set the timeout to ensure the transaction has appeared on the blockchain. time.Sleep(5 * time.Second) // Get the information about the transaction from the node. txInfo, _, err := nodeClient.Transactions.Info(contextCreateTx, *tx.ID) if err != nil { panic(err) } // Print the transaction info. fmt.Printf("Transaction info: %+v\n", txInfo) }
- Install the dependencies:
go mod tidy
- Run the application
go mod run waves.go