Nodejs sdk, company identity and client infos

Hello, I’ve successfully created a company identity and imported the key file into concordium node through the concordium client utility (concordium-client account update-keys KEY-FILE.json) and if I try to send a transaction with the client (concordium-client transaction send --receiver xx --amount xx --sender xx) it says that it can’t find the default account. I tried to import it through (concordium-client config account import KEY-FILE.json) and add-keys but it files with:

  • Error: Cannot decode keys: Error in $.accountKeys: parsing Word8 failed, Failed reading: takeWhile1.
  • Error: Cannot import accounts: Cannot decode wallet export: Error in $: key "type" not found.

Moreover, how I can get these account signer and what if I want to use some gRPC methods that aren’t implemented in node sdk such as getAccountList()?

Hello, and thank you for reaching out to Concordium Tech Support.

I just want to be sure that the ID creation process was successful. Did you receive id-object.json from Notabene?

Can I get the name of your node?

Regards,

Concordium Tech Support

node name: sellix
yes I’ve received id-object and I’ve got the account-keys.json

Hello Federico

I can see your node on CCDscan.io. Please update to the newest versions both Client and your Node.
Downloads - Mainnet — Concordium documentation

Regards,
Concordium Tech Support

I’ve performed the upgrade to 4.4.4 regarding mainnet-node while I’ve the 4.2.0 concordium client.
Still not working.

Can you retrace your steps a bit?

The command concordium-client account update-keys KEY-FILE.json is not for importing keys, it is for updating existing keys. The command for importing keys is config account import --name xx ....

Regarding importing into the nodeJS, have you tried using the buildBasicAccountSigner as documented here concordium-node-sdk-js/README.md at f1e43d89dc1729bdedf9105def1ae829fc68fd77 · Concordium/concordium-node-sdk-js · GitHub

If the file (account-keys) is encrypted you can decrypt it using the `utils tool.

# ./concordium-client_4.2.0-0 config account import --name default ./enterprise-identities/account-keys.json 
Error: Cannot import accounts: Cannot decode wallet export: Error in $: key "type" not found.

It isn’t encrypted.

Regarding buildBasicAccountSigner how do I get signing keys and build the signatures?

The siging key is in the account-keys file you have generated using the user_cli.

You need to use the --format=genesis option to import the keys generated from user_cli into concordium client, see concordium-base/user-cli.md at main · Concordium/concordium-base · GitHub

Note that you cannot import the initial account like that for technical and legacy reasons. But you can create additional accounts as described in concordium-base/user-cli.md at main · Concordium/concordium-base · GitHub

ok, with the format genesis option it worked, but from what I can see concordium client reads only 1 address… does concordium has subaddresses, how do they work?

There is one account created. You can create up to 25 additional accounts using one identity object.

Each account can have up to 2^24 addresses. There is still one account, with one balance, but you can use different addresses to refer to it, in transactions, etc. That gives you a sub-account structure in a sense.

You can show aliases using concordium-client account show-alias function, see Concordium Client — Concordium documentation

The NodeJS SDK also has a function to generate aliases of a given account.

./concordium-client_4.2.0-0 account show-alias default  --alias 1
The requested alias for address XXXX is YYYY

./concordium-client_4.2.0-0  transaction send --receiver ZZZZ --amount 10 --sender YYYY
Error: Key directory for account 'YYYY' not found.
       Did you forget to add the account (using 'config account add')?

You should use

--sender default --alias 1
// The signatures used to sign the transaction must be provided in a structured way,
// so that each signature can be mapped to the credential that signed the transaction.
// In this example we assume the key used was from the credential with index 0, and it
// was the key with index 0.

How does work this? if I add an additional account and I use it for the transaction it becomes index 1?

No, this is per-account. Each account may have more than one credential, and each credential may have more than one key.

I assume you don’t make use of that, so that indices will always be 0, 0.

I haven’t found any function that let me use aliases in nodejs sdk, maybe the sender param in the transaction header accepts the alias “id”?
Furthermore,
I’m trying to sign the transaction using the examples in common, (Create a simple transfer), as:

const signer = buildBasicAccountSigner(signingKey)
const transactionSignature = signTransaction(simpleTransferAccountTransaction, signer)

but the function signTransaction gives this error:

node_modules/buffer/index.js:403
      length += list[i].length
                        ^

TypeError: Cannot read properties of undefined (reading 'length')
    at Function.concat (/node_modules/buffer/index.js:403:25)
    at serializeAccountTransactionHeader (/node_modules/@concordium/common-sdk/lib/serialization.js:54:28)
    at getAccountTransactionSignDigest (/node_modules/@concordium/common-sdk/lib/serialization.js:128:30)
    at signTransaction (node_modules/@concordium/common-sdk/lib/signHelpers.js:59:72)
    at file:///main.js:39:30
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

I’m using latest version of both common and node sdks.

Hi, the error you are getting looks like the sender param of the transaction header is not an AccountAddress object, which it needs to be.

The nodejs sdk does have a function getAlias for generating an alias, but it is documented in the common-sdk’s documentation (and node-sdk re-exports it):

This function is to generate an alias by an address…
I don’t know account addresses.
I want to use aliases or get addresses in order to send transaction by using multiple addresses.

You should have an address from the initial account that was created along with your identity.
(and its address should be in the account-keys.json you have generated, as a top level field called “address”. I assume that is were you got the signingKey for buildBasicAccountSigner)

The alias is created based on the address you give it, so you need an address to generate an alias for it.

You also need the address to build the header for simpleTransferAccountTransaction. That might be the reason you got an error when signing, because the sender needs to be “sender: new AccountAddress(XXXX)”, where XXXX is your address.

well, so giving as input the main address and the alias index the getAlias() function will return me the subaddress?

edit: works

1 Like

Yes, that is the behaviour of the function. And the approach to aliases in general.