'alias' is not created via REST API

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…

Code:

const fetch = require(‘node-fetch’);
const generator = require(’@waves/signature-generator’);
const signAdapter = require(’@waves/signature-adapter’);
const transactions = require(’@waves/waves-transactions’);
const TEST_NODE_ADDRESS = ‘https://pool.testnet.wavesnodes.com’;

const nodeAddress = TEST_NODE_ADDRESS;
generator.config.set({ networkByte: generator.TESTNET_BYTE });

// seedMain - account with a lot of Waves
const seedMain = /* seed phrase here */;

broadcastTransaction = (tx) => {
//return transactions.broadcast(tx, nodeAddress);
return fetch(nodeAddress + ‘/transactions/broadcast’, {
method: ‘POST’,
headers: {
‘Accept’: ‘application/json’,
‘Content-Type’: ‘application/json’
},
body: JSON.stringify(tx)
})
.then(x =>
x.json()
)
.catch(e =>
Promise.reject(e)
);
};

let seed = generator.Seed.create().phrase;

const adapter = new signAdapter.SeedAdapter(seed);
adapter.getAddress().then(address => {
const dataTx = transactions.transfer({
recipient: address,
amount: 1000000
}, seedMain);// seedMain - account with a lot of Waves
broadcastTransaction(dataTx).then(tx => {
const alias = ‘test_alias-’ + Date.now();
const aliasTx = transactions.alias({
alias: alias
}, seed);
broadcastTransaction(aliasTx).then(tx => {
console.log(Transaction alias: ${JSON.stringify(tx)});
// tx.error = 112
}).catch(err =>
console.log(“Error”)
);
}).catch(err => console.log(“Error”));
});

Error:

“State check failed. Reason: Script doesn’t exist and proof doesn’t validate as signature for …”

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?

Could you provide me a sample how to create alias programmatically using your libraries?

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

Here the result of running the program: http://wavesexplorer.com/tx/HabJnxZauHSsdzjv6PY49R1KUsnw9wErGQ8wyip6nXcu

1 Like

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.

1 Like

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.

1 Like

@alexey.kiselev Thanks for detailed explanation

@siem
Could you clarify how I can do it using signature-adapter or signature-generator libraries?

Hi, waves-transaction library was fixed. You can try version >= 3.0.26

1 Like