Could you explain what type of problem I have when trying to create alias for new generated address.
Firstly, I generate seed, then get address, then put some waves to this address from my account, then create alias for new address and without success.
Is these steps correct or something wrong? Should I do something to register new account inside the blockchain?
I extracted my code and refactor it to demonstrate and here still the same error…
Looks like you’ve singed the transaction with the wrong private key or put the incorrect public key into the transaction. The error says that the node failed to validate the transaction’s signature.
The alias has to be unique among all aliases on the blockchain.
So, and what’s wrong in my code?
I’ve provided a most little sample, which raises the error. Sample has full code to reproduce the issue, I’ve just cut my seed (=seedMain) from it.
Could support team Waves check what’s wrong?
I’m currently working on gowaves project, so, I can provide you with the example of how to create an alias using our Go Waves client library:
import (
"context"
"net/http"
"time"
"github.com/wavesplatform/gowaves/pkg/client"
"github.com/wavesplatform/gowaves/pkg/crypto"
"github.com/wavesplatform/gowaves/pkg/proto"
)
func main() {
// Create sender's public key from BASE58 string
sender, err := crypto.NewPublicKeyFromBase58("<your-public-key>")
if err != nil {
panic(err)
}
// Create sender's private key from BASE58 string
pk, err := crypto.NewSecretKeyFromBase58("<your-private-key>")
if err != nil {
panic(err)
}
// Current time in milliseconds
ts := time.Now().Unix() * 1000
// Create new alias with blockchain byte 'T' for TestNet
alias, err := proto.NewAlias('T', "testnetnode2")
if err != nil {
panic(err)
}
// New CreateAlias Transaction
tx, err := proto.NewUnsignedCreateAliasV1(sender, *alias, 100000, uint64(ts))
if err != nil {
panic(err)
}
// Sing the transaction with the private key
err = tx.Sign(pk)
// Here the trickiest part, we have to convert the transaction to the request,
// because the API accepts not the alias string representation, but alias value only
req := client.AliasBroadcastReq{
SenderPublicKey: sender,
Fee: tx.Fee,
Timestamp: tx.Timestamp,
Signature: *tx.Signature,
Alias: tx.Alias.Alias,
}
// Create new HTTP client to send the transaction to public TestNet nodes
client, err := client.NewClient(client.Options{BaseUrl: "https://testnodes.wavesnodes.com", Client: &http.Client{}})
if err != nil {
panic(err)
}
// Context to cancel the request execution on timeout
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
// Send the transaction to the network
_, _, err = client.Alias.Broadcast(ctx, req)
if err != nil {
panic(err)
}
}
I need to create private key to change alias?
I do not understand Go, and it is independent to my problem. Looks like JS library do not work with aliases - am I right?
No, you don’t need to create a new private key. But you have to use one to sign the transaction that creates an alias. You should use the private key that was used to create the particular account to which you want to crate an alias.
Basically, from the seed phrase you create an account seed, from the account seed you create the private key and the public key. From that public key you generate the address. If you want to create an alias to the address, you have to sign the CreateAlias transaction with the private key from which the public key and the address were created.
I’ll try to find someone to help you with JS library.
Hello! Yes, it seems like aliases are bugged in ‘waves-transactions’ library. For now you can create them via signature-adapter or signature-generator. We will fix this asap.