You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: source/mainnet/net/guides/wallet-sdk/wallet-sdk-account-transaction.rst
+79-46Lines changed: 79 additions & 46 deletions
Original file line number
Diff line number
Diff line change
@@ -7,15 +7,16 @@ Submit a transaction to a Concordium node
7
7
The following sections document the requirements for creating an account transaction, signing it, and
8
8
sending it to a Concordium node.
9
9
10
-
* `Construct an account transaction`_
11
-
* `Sign an account transaction`_
10
+
* `Construct and sign an account transaction`_
12
11
* `Send an account transaction to a Concordium node`_
13
12
14
-
++++++++++++++++++++++++++++++++
15
-
Construct an account transaction
16
-
++++++++++++++++++++++++++++++++
13
+
+++++++++++++++++++++++++++++++++++++++++
14
+
Construct and sign an account transaction
15
+
+++++++++++++++++++++++++++++++++++++++++
17
16
18
-
This example constructs a simple transfer, which is an account transaction that moves an amount of CCD from one account to another. For other transaction types, the steps are similar, but the exact fields that must be provided for the payload will be different.
17
+
This example constructs and signs a simple transfer, which is an account transaction that moves an amount of CCD from one account to another. For other transaction types, the steps are similar, but the exact fields that must be provided for the payload will be different. Note that Concordium as a whole supports multi-signature transactions, but for the purpose of this example it will demonstrate how to sign for an account with a single credential that has a single key.
18
+
19
+
Note that when the transaction has been signed anyone with the signature and the transaction will be able to send it to a Concordium node. Therefore it is very important that a wallet requests user approval before utilizing their signing keys.
19
20
20
21
.. tabs::
21
22
@@ -29,6 +30,7 @@ This example constructs a simple transfer, which is an account transaction that
29
30
AccountAddress,
30
31
AccountTransaction,
31
32
AccountTransactionHeader,
33
+
buildBasicAccountSigner,
32
34
CcdAmount,
33
35
ConcordiumGRPCWebClient,
34
36
ConcordiumHdWallet,
@@ -73,44 +75,6 @@ This example constructs a simple transfer, which is an account transaction that
73
75
header,
74
76
};
75
77
76
-
.. tab::
77
-
78
-
Kotlin (Android)
79
-
80
-
TODO Write the Kotlin example.
81
-
82
-
.. tab::
83
-
84
-
Swift (iOS)
85
-
86
-
The Swift SDK for iOS is still in development.
87
-
88
-
+++++++++++++++++++++++++++
89
-
Sign an account transaction
90
-
+++++++++++++++++++++++++++
91
-
92
-
Having constructed an account transaction, the next step is to sign it. It is important that the key used to sign an account transaction matches the sender address provided in the account transaction header. Note that Concordium as a whole supports multi-signature transactions, but for the purpose of this example it will demonstrate how to do it for an account with a single credential that has a single key.
93
-
94
-
Note that when the transaction has been signed anyone with the signature and the transaction will be able to send it to a Concordium node. Therefore it is very important that a wallet requests user approval before utilizing their signing keys.
95
-
96
-
.. tabs::
97
-
98
-
.. tab::
99
-
100
-
TypeScript (Web)
101
-
102
-
.. code-block:: javascript
103
-
104
-
import {
105
-
buildBasicAccountSigner,
106
-
ConcordiumHdWallet,
107
-
signTransaction,
108
-
} from'@concordium/web-sdk';
109
-
110
-
constseedPhrase='fence tongue sell large master side flock bronze ice accident what humble bring heart swear record valley party jar caution horn cushion endorse position';
111
-
constnetwork='Testnet'; // Or Mainnet, if working on mainnet.
fun createTransferTransaction(): TransferTransaction {
107
+
val seedPhrase = "fence tongue sell large master side flock bronze ice accident what humble bring heart swear record valley party jar caution horn cushion endorse position"
108
+
109
+
@OptIn(ExperimentalStdlibApi::class)
110
+
val seedAsHex = Mnemonics.MnemonicCode(seedPhrase!!.toCharArray()).toSeed().toHexString()
111
+
val network = Network.TESTNET // Or Network.MAINNET, if working on mainnet.
112
+
val wallet = ConcordiumHdWallet.fromHex(seedAsHex, Network.TESTNET)
113
+
114
+
val connection = Connection.newBuilder()
115
+
.host(nodeAddress)
116
+
.port(nodePort)
117
+
.useTLS(TLSConfig.auto())
118
+
.build()
119
+
val client = ClientV2.from(connection)
120
+
121
+
val cryptographicParameters = client.getCryptographicParameters(BlockQuery.BEST)
122
+
123
+
val credId = wallet.getCredentialId(identityProviderIndex, identityIndex, credNumber, cryptographicParameters.onChainCommitmentKey.toHex())
124
+
val sender = AccountAddress.from(CredentialRegistrationId.from(credId))
125
+
126
+
val toAddress = AccountAddress.from("4QkqdUnrjShrUrHpE96odLM6J77nWzEryifzqNnwNk4FYNge8a")
127
+
val amount = CCDAmount.from(5000000)
128
+
129
+
val nonce = client.getNextAccountSequenceNumber(sender)
130
+
val expiry = Expiry.createNew().addMinutes(5)
131
+
132
+
val signingKey = wallet.getAccountSigningKey(identityProviderIndex, identityIndex, credNumber)
const seedPhrase ='fence tongue sell large master side flock bronze ice accident what humble bring heart swear record valley party jar caution horn cushion endorse position';
@@ -89,7 +90,93 @@ The following example demonstrates how a credential deployment transaction is cr
val global = client.getCryptographicParameters(BlockQuery.BEST)
131
+
132
+
val seedPhrase = "fence tongue sell large master side flock bronze ice accident what humble bring heart swear record valley party jar caution horn cushion endorse position"
133
+
@OptIn(ExperimentalStdlibApi::class)
134
+
val seedAsHex = Mnemonics.MnemonicCode(seedPhrase.toCharArray()).toSeed().toHexString()
135
+
val wallet = ConcordiumHdWallet.fromHex(seedAsHex, Network.TESTNET)
136
+
137
+
val attributeRandomness: MutableMap<AttributeType, String> = EnumMap(AttributeType::class.java)
138
+
for (attrType in identity.attributeList.chosenAttributes.keys) {
fun signCredentialDeployment(credentialDeployment: CredentialDeploymentDetails): ByteArray {
240
+
val seedPhrase = "fence tongue sell large master side flock bronze ice accident what humble bring heart swear record valley party jar caution horn cushion endorse position"
241
+
@OptIn(ExperimentalStdlibApi::class)
242
+
val seedAsHex = Mnemonics.MnemonicCode(seedPhrase.toCharArray()).toSeed().toHexString()
243
+
val wallet = ConcordiumHdWallet.fromHex(seedAsHex, Network.TESTNET)
244
+
245
+
// The credentialCounter and the identityIndex must identical to what was used when deriving
246
+
// the keys to create the credential deployment transaction.
247
+
val credentialCounter = 0
248
+
val identityIndex = 0
249
+
250
+
// The indentityProvider index must be indentical to the index of the identity provider
251
+
// that was used to create the identity that the credential is for.
252
+
val identityProviderIndex = 0
253
+
254
+
val credentialDeploymentSignDigest = Credential.getCredentialDeploymentSignDigest(credentialDeployment)
0 commit comments