Examples

Initialization

1import ArkBuilder

Transactions

A transaction is an object specifying the transfer of funds from the sender’s wallet to the recipient’s. Each transaction must be signed by the sender’s private key to prove authenticity and origin. After broadcasting through the client SDK , a transaction is permanently incorporated in the blockchain by a Delegate Node.

Sign

The crypto SDK can sign a transaction using your private key or passphrase (from which the private key is generated). Ensure you are familiar with digital signatures before using the crypto SDKs.

1// Creating a transaction automatically signs it with the provides passphrase(s)
2let transfer = ArkBuilder.buildTransfer(
3 "secret passphrase",
4 secondPassphrase: nil,
5 to: "DBk4cPYpqp7EBcvkstVDpyX7RQJNHxpMg8",
6 amount: 10000000,
7 vendorField: "this is a tx from Swift")
8 
9print(type(of: transfer))
10 
11>>> ArkTransaction

Serialize (AIP11)

Serialization of a transaction object ensures it is compact and properly formatted to be incorporated in the ARK blockchain. If you are using the crypto SDK in combination with the public API SDK, you should not need to serialize manually.

1let serialized = ArkSerializer.serialize(transaction: transaction)
2 
3print(type(of: serialized))
4 
5>>> String

Deserialize (AIP11)

A serialized transaction may be deserialized for inspection purposes. The public API does not return serialized transactions, so you should only need to deserialize in exceptional circumstances.

1let deserialized = ArkDeserializer.deserialize(serialized: serialized)
2 
3print(type(of: deserialized))
4 
5>>> ArkTransaction

Message

The crypto SDK not only supports transactions but can also work with other arbitrary data (expressed as strings).

Sign

Signing a string works much like signing a transaction: in most implementations, the message is hashed, and the resulting hash is signed using the private key or passphrase.

1let message = ArkMessage.sign(message: "Hello World", passphrase: "this is a top secret passphrase")
2 
3print(type(of: message))
4 
5>>> ArkMessage?

Verify

A message’s signature can easily be verified by hash, without the private key that signed the message, by using the verify method.

1let message = ArkMessage(publicKey: "034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192",
2 signature: "304402200fb4adddd1f1d652b544ea6ab62828a0a65b712ed447e2538db0caebfa68929e02205ecb2e1c63b29879c2ecf1255db506d671c8b3fa6017f67cfd1bf07e6edd1cc8",
3 message: "Hello World")
4 
5print(type(of: message.verify()))
6 
7>>> Bool

Identities

The identities class allows for the creation and inspection of keyPairs from passphrases. Here you find vital functions when creating transactions and managing wallets.

Derive the Address from a Passphrase

1let address = ArkAddress.from(passphrase: "this is a top secret passphrase")
2 
3print(type(of: address))
4 
5>>> String

Derive the Address from a Public Key

1let address = ArkAddress.from(publicKey: "034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192")
2 
3print(type(of: address))
4 
5>>> String

Derive the Address from a Private Key

1let address = ArkAddress.from(privateKey: ArkPrivateKey.from(hex: "d8839c2432bfd0a67ef10a804ba991eabba19f154a3d707917681d45822a5712"))
2 
3print(type(of: address))
4 
5>>> String

Validate an Address

1let address = ArkAddress.validate(address: "D61mfSggzbvQgTUe6JhYKH2doHaqJ3Dyib")
2 
3print(type(of: address))
4 
5>>> Bool

Private Key

As the name implies, private keys and passphrases are to remain private. Never store these unencrypted and minimize access to these secrets

Derive the Private Key from a Passphrase

1let privateKey = ArkPrivateKey.from(passphrase: "this is a top secret passphrase")
2 
3print(type(of: privateKey))
4 
5>>> PrivateKey

Derive the Private Key Instance Object from a Hexadecimal Encoded String

1let privateKey = ArkPrivateKey.from(hex: "d8839c2432bfd0a67ef10a804ba991eabba19f154a3d707917681d45822a5712")
2 
3print(type(of: privateKey))
4 
5>>> PrivateKey

Derive the Private Key from a WIF

1This function has not been implemented in this client library.

Public Key

Public Keys may be freely shared, and are included in transaction objects to validate the authenticity.

Derive the Public Key from a Passphrase

1let publicKey = ArkPublicKey.from(passphrase: "this is a top secret passphrase")
2 
3print(type(of: publicKey))
4 
5>>> PublicKey

Derive the Public Key Instance Object from a Hexadecimal Encoded String

1let publicKey = ArkPublicKey.from(hex: "d8839c2432bfd0a67ef10a804ba991eabba19f154a3d707917681d45822a5712")
2 
3print(type(of: publicKey))
4 
5>>> PublicKey

Validate a Public Key

1This function has not been implemented in this client library.

WIF

The WIF should remain secret, just like your passphrase and private key.

Derive the WIF from a Passphrase

1let wif = WIF.from(passphrase: "this is a top secret passphrase")
2 
3print(type(of: wif))
4 
5>>> String
Last updated 2 years ago
Edit Page
Share: