API Documentation
Identity
Type | Name | Required | Description |
---|---|---|---|
string | passphrase | Yes | The passphrase used to generate the address. |
Return Value
This function returns an address derived from the provided passphrase as a string.
address, err := AddressFromPassphrase("super secret passphrase")
>> "0x2289577F3784788784226Eb41E9B0ca9705C7C37"
Type | Name | Required | Description |
---|---|---|---|
string | address | Yes | The address to be validated. |
Return Value
This function checks if the provided address is valid. Returns a boolean value indicating validity.
isValid, err := ValidateAddress("0x2289577F3784788784226Eb41E9B0ca9705C7C37")
>> true
Get BLS private key from passphrase
func BLSPrivateKeyFromPassphrase(passphrase string) (*BLSPrivateKey, error)
Parameters
Type | Name | Required | Description |
---|---|---|---|
string | passphrase | Yes | The passphrase used to generate the BLS private key. |
Return Value
This function returns a BLSPrivateKey object derived from the provided passphrase.
blsPrivateKey, err := BLSPrivateKeyFromPassphrase("super secret passphrase")
>> &BLSPrivateKey{}
Get BLS public key from passphrase
func BLSPublicKeyFromPassphrase(passphrase string) (*BLSPublicKey, error)
Parameters
Type | Name | Required | Description |
---|---|---|---|
string | passphrase | Yes | The passphrase used to generate the BLS public key. |
Return Value
This function returns a BLSPublicKey object derived from the provided passphrase.
blsPublicKey, err := BLSPublicKeyFromPassphrase("super secret passphrase")
>> &BLSPublicKey{}
Get private key from passphrase
func PrivateKeyFromPassphrase(passphrase string) (*PrivateKey, error)
Parameters
Type | Name | Required | Description |
---|---|---|---|
string | passphrase | Yes | The passphrase used to generate the private key. |
Return Value
This function returns a PrivateKey object derived from the provided passphrase.
privateKey, err := PrivateKeyFromPassphrase("super secret passphrase")
>> &PrivateKey{}
Get public key from passphrase
func PublicKeyFromPassphrase(passphrase string) (*PublicKey, error)
Parameters
Type | Name | Required | Description |
---|---|---|---|
string | passphrase | Yes | The passphrase used to generate the public key. |
Return Value
This function returns a PublicKey object derived from the provided passphrase.
publicKey, err := PublicKeyFromPassphrase("super secret passphrase")
>> &PublicKey{}
Fee
Type | Name | Required | Description |
---|---|---|---|
uint16 | transactionType | Yes | The transaction type for which to get the fee. |
Return Value
This function returns the fee for the specified transaction type as a FlexToshi value.
fee := GetFee(TRANSACTION_TYPES.Transfer)
>> 10000000
Type | Name | Required | Description |
---|---|---|---|
uint16 | transactionType | Yes | The transaction type for which to set the fee. |
FlexToshi | value | Yes | The fee value to set for the given transaction type. |
Return Value
This function sets the fee for the specified transaction type.
SetFee(TRANSACTION_TYPES.Transfer, 5000000)
>> None
Network
Type | Name | Required | Description |
---|---|---|---|
*Network | network | Yes | Network configuration object to set for the crypto library. Options: Mainnet, Devnet, Testnet. |
Return Value
This function sets the network configuration (epoch, version, and WIF) based on the provided network object (Mainnet, Devnet, or Testnet).
SetNetwork(NETWORKS_MAINNET)
>> None
This function returns the current network configuration object.
network := GetNetwork()
>> &Network{Epoch: time.Date(2017, 3, 21, 13, 00, 0, 0, time.UTC), Version: 30, Wif: 170}
Transactions
This method returns the transaction ID as a hexadecimal string.
transactionId := transaction.GetId()
>> "d2b6f58b41e8..."
Sign a transaction with a passphrase
func (transaction *Transaction) Sign(passphrase string)
Parameters
Type | Name | Required | Description |
---|---|---|---|
string | passphrase | Yes | The passphrase associated with the account sending this transaction. |
Return Value
This method signs the transaction using the provided passphrase.
transaction.Sign("your passphrase")
>> None
Sign a multi-signature transaction with a passphrase
func (transaction *Transaction) SignMulti(signerIndex int, passphrase string)
Parameters
Type | Name | Required | Description |
---|---|---|---|
int | signerIndex | Yes | Index of the signer in the multi-signature group. |
string | passphrase | Yes | The passphrase of the signer. |
Return Value
This method signs a multi-signature transaction with the given signer index and passphrase.
transaction.SignMulti(0, "your passphrase")
>> None
Add a second signature to a transaction
func (transaction *Transaction) SecondSign(passphrase string)
Parameters
Type | Name | Required | Description |
---|---|---|---|
string | passphrase | Yes | The second passphrase associated with the account sending this transaction. |
Return Value
This method adds a second signature to the transaction using the provided second passphrase.
transaction.SecondSign("your second passphrase")
>> None
Verify the transaction signature
func (transaction *Transaction) Verify(multiSignatureAsset ...*MultiSignatureRegistrationAsset) (bool, error)
Parameters
Type | Name | Required | Description |
---|---|---|---|
[]*MultiSignatureRegistrationAsset | multiSignatureAsset | No | Optional multi-signature asset to verify the multi-signature transaction. |
Return Value
This method verifies the transaction signature. Returns true if the signature is valid, otherwise false.
isValid, err := transaction.Verify()
>> true, nil
Verify the second signature of the transaction
func (transaction *Transaction) SecondVerify(secondPublicKey *PublicKey) (bool, error)
Parameters
Type | Name | Required | Description |
---|---|---|---|
*PublicKey | secondPublicKey | Yes | The public key to verify the second signature against. |
Return Value
This method verifies the second signature of the transaction. Returns true if the second signature is valid, otherwise false.
isValid, err := transaction.SecondVerify(secondPublicKey)
>> true, nil
Convert the transaction to a dictionary
func (transaction *Transaction) ToMap() map[string]interface{}
Return Value
This method returns a dictionary representation of the transaction.
transactionMap := transaction.ToMap()
>> map[string]interface{}{"id": "d2b6f58b41e8...", "amount": 100000000, ...}
Return Value
This method returns a JSON string representation of the transaction.
transactionJson, err := transaction.ToJson()
>> '{"id": "d2b6f58b41e8...", "amount": 100000000, ...}', nil
Create a transfer transaction
func BuildTransfer(transaction *Transaction, passphrase string, secondPassphrase string) *Transaction
Parameters
Type | Name | Required | Description |
---|---|---|---|
*Transaction | transaction | Yes | Transaction object to be populated and signed. |
string | passphrase | Yes | Passphrase associated with the account sending this transaction. |
string | secondPassphrase | No | Second passphrase for the account, if available. |
Return Value
This function sets all fields and signs a transfer transaction.
transferTransaction := BuildTransfer(transaction, "your passphrase", "")
>> &Transaction{Type: 0, ...}
Create a vote transaction
func BuildVote(transaction *Transaction, passphrase string, secondPassphrase string) *Transaction
Parameters
Type | Name | Required | Description |
---|---|---|---|
*Transaction | transaction | Yes | Transaction object to be populated and signed. |
string | passphrase | Yes | Passphrase associated with the account sending this transaction. |
string | secondPassphrase | No | Second passphrase for the account, if available. |
Return Value
This function sets all fields and signs a vote transaction.
voteTransaction := BuildVote(transaction, "your passphrase", "")
>> &Transaction{Type: 3, ...}
Create a validator registration transaction
func BuildValidatorRegistration(transaction *Transaction, passphrase string, secondPassphrase string) *Transaction
Parameters
Type | Name | Required | Description |
---|---|---|---|
*Transaction | transaction | Yes | Transaction object to be populated and signed. |
string | passphrase | Yes | Passphrase associated with the account sending this transaction. |
string | secondPassphrase | No | Second passphrase for the account, if available. |
Return Value
This function sets all fields and signs a validator registration transaction.
validatorRegistrationTransaction := BuildValidatorRegistration(transaction, "your passphrase", "")
>> &Transaction{Type: 2, ...}
Create a multi-signature registration transaction
func BuildMultiSignatureRegistration(transaction *Transaction, passphrase string, secondPassphrase string) *Transaction
Parameters
Type | Name | Required | Description |
---|---|---|---|
*Transaction | transaction | Yes | Transaction object to be populated and signed. |
string | passphrase | Yes | Passphrase associated with the account sending this transaction. |
string | secondPassphrase | No | Second passphrase for the account, if available. |
Return Value
This function sets all fields and signs a multi-signature registration transaction.
multiSignatureTransaction := BuildMultiSignatureRegistration(transaction, "your passphrase", "")
>> &Transaction{Type: 4, ...}
Create a multi-payment transaction
func BuildMultiPayment(transaction *Transaction, passphrase string, secondPassphrase string) *Transaction
Parameters
Type | Name | Required | Description |
---|---|---|---|
*Transaction | transaction | Yes | Transaction object to be populated and signed. |
string | passphrase | Yes | Passphrase associated with the account sending this transaction. |
string | secondPassphrase | No | Second passphrase for the account, if available. |
Return Value
This function sets all fields and signs a multi-payment transaction.
multiPaymentTransaction := BuildMultiPayment(transaction, "your passphrase", "")
>> &Transaction{Type: 6, ...}
Create a validator resignation transaction
func BuildValidatorResignation(transaction *Transaction, passphrase string, secondPassphrase string) *Transaction
Parameters
Type | Name | Required | Description |
---|---|---|---|
*Transaction | transaction | Yes | Transaction object to be populated and signed. |
string | passphrase | Yes | Passphrase associated with the account sending this transaction. |
string | secondPassphrase | No | Second passphrase for the account, if available. |
Return Value
This function sets all fields and signs a validator resignation transaction.
validatorResignationTransaction := BuildValidatorResignation(transaction, "your passphrase", "")
>> &Transaction{Type: 7, ...}
Serializer
Serialize a transaction
func (transaction *Transaction) serialize(includeSignature bool, includeSecondSignature bool, includeMultiSignatures bool) []byte
Parameters
Type | Name | Required | Description |
---|---|---|---|
bool | includeSignature | Yes | Whether to include the transaction signature in the serialized data. |
bool | includeSecondSignature | Yes | Whether to include the second signature in the serialized data. |
bool | includeMultiSignatures | Yes | Whether to include all multi-signatures in the serialized data. |
Return Value
This method serializes the transaction according to the provided parameters.
serializedTransaction := transaction.Serialize(true, true, true)
>> []byte{0xff, 0x01, 0x1e, ...}
Serialize transaction header
func (transaction *Transaction) serializeHeader(ser *bytes.Buffer)
Parameters
Type | Name | Required | Description |
---|---|---|---|
*bytes.Buffer | ser | Yes | Buffer to which the serialized header will be written. |
Return Value
This method serializes the transaction header into the provided buffer.
ser := new(bytes.Buffer)
transaction.serializeHeader(ser)
>> None
Serialize transaction vendor field
func (transaction *Transaction) serializeVendorField(ser *bytes.Buffer)
Parameters
Type | Name | Required | Description |
---|---|---|---|
*bytes.Buffer | ser | Yes | Buffer to which the serialized vendor field will be written. |
Return Value
This method serializes the transaction vendor field into the provided buffer.
ser := new(bytes.Buffer)
transaction.serializeVendorField(ser)
>> None
Serialize transaction type-specific data
func (transaction *Transaction) serializeTypeSpecific(ser *bytes.Buffer)
Parameters
Type | Name | Required | Description |
---|---|---|---|
*bytes.Buffer | ser | Yes | Buffer to which the serialized type-specific data will be written. |
Return Value
This method serializes the transaction type-specific data into the provided buffer.
ser := new(bytes.Buffer)
transaction.serializeTypeSpecific(ser)
>> None
Serialize transaction signatures
func (transaction *Transaction) serializeSignatures(ser *bytes.Buffer, includeSignature bool, includeSecondSignature bool, includeMultiSignatures bool)
Parameters
Type | Name | Required | Description |
---|---|---|---|
*bytes.Buffer | ser | Yes | Buffer to which the serialized signatures will be written. |
bool | includeSignature | Yes | Whether to include the transaction signature in the serialized data. |
bool | includeSecondSignature | Yes | Whether to include the second signature in the serialized data. |
bool | includeMultiSignatures | Yes | Whether to include all multi-signatures in the serialized data. |
Return Value
This method serializes the transaction signatures into the provided buffer based on the provided flags.
ser := new(bytes.Buffer)
transaction.serializeSignatures(ser, true, false, true)
>> None
Serialize a transfer transaction
func (transaction *Transaction) serializeTransfer(ser *bytes.Buffer)
Parameters
Type | Name | Required | Description |
---|---|---|---|
*bytes.Buffer | ser | Yes | Buffer to which the serialized transfer transaction will be written. |
Return Value
This method serializes the transfer transaction into the provided buffer.
ser := new(bytes.Buffer)
transaction.serializeTransfer(ser)
>> None
Serialize a vote transaction
func (transaction *Transaction) serializeVote(ser *bytes.Buffer)
Parameters
Type | Name | Required | Description |
---|---|---|---|
*bytes.Buffer | ser | Yes | Buffer to which the serialized vote transaction will be written. |
Return Value
This method serializes the vote transaction into the provided buffer.
ser := new(bytes.Buffer)
transaction.serializeVote(ser)
>> None
Serialize a validator registration transaction
func (transaction *Transaction) serializeValidatorRegistration(ser *bytes.Buffer)
Parameters
Type | Name | Required | Description |
---|---|---|---|
*bytes.Buffer | ser | Yes | Buffer to which the serialized validator registration transaction will be written. |
Return Value
This method serializes the validator registration transaction into the provided buffer.
ser := new(bytes.Buffer)
transaction.serializeValidatorRegistration(ser)
>> None
Serialize a multi-signature registration transaction
func (transaction *Transaction) serializeMultiSignatureRegistration(ser *bytes.Buffer)
Parameters
Type | Name | Required | Description |
---|---|---|---|
*bytes.Buffer | ser | Yes | Buffer to which the serialized multi-signature registration transaction will be written. |
Return Value
This method serializes the multi-signature registration transaction into the provided buffer.
ser := new(bytes.Buffer)
transaction.serializeMultiSignatureRegistration(ser)
>> None
Serialize a multi-payment transaction
func (transaction *Transaction) serializeMultiPayment(ser *bytes.Buffer)
Parameters
Type | Name | Required | Description |
---|---|---|---|
*bytes.Buffer | ser | Yes | Buffer to which the serialized multi-payment transaction will be written. |
Return Value
This method serializes the multi-payment transaction into the provided buffer.
ser := new(bytes.Buffer)
transaction.serializeMultiPayment(ser)
>> None
Serialize a validator resignation transaction
func (transaction *Transaction) serializeValidatorResignation(ser *bytes.Buffer)
Parameters
Type | Name | Required | Description |
---|---|---|---|
*bytes.Buffer | ser | Yes | Buffer to which the serialized validator resignation transaction will be written. |
Return Value
This method serializes the validator resignation transaction into the provided buffer.
ser := new(bytes.Buffer)
transaction.serializeValidatorResignation(ser)
>> None
Serialize a username registration transaction
func (transaction *Transaction) serializeUsernameRegistration(ser *bytes.Buffer)
Parameters
Type | Name | Required | Description |
---|---|---|---|
*bytes.Buffer | ser | Yes | Buffer to which the serialized username registration transaction will be written. |
Return Value
This method serializes the username registration transaction into the provided buffer.
ser := new(bytes.Buffer)
transaction.serializeUsernameRegistration(ser)
>> None
Serialize a username resignation transaction
func (transaction *Transaction) serializeUsernameResignation(ser *bytes.Buffer)
Parameters
Type | Name | Required | Description |
---|---|---|---|
*bytes.Buffer | ser | Yes | Buffer to which the serialized username resignation transaction will be written. |
Return Value
This method serializes the username resignation transaction into the provided buffer.
ser := new(bytes.Buffer)
transaction.serializeUsernameResignation(ser)
>> None
Deserializer
Type | Name | Required | Description |
---|---|---|---|
string | serialized | Yes | Hex-encoded serialized transaction string. |
Return Value
This function deserializes a hex-encoded serialized transaction string into a `Transaction` object.
transaction := DeserializeTransaction("ff011e0300000000000000000000000000...")
>> &Transaction{
Type: 0,
TypeGroup: 1,
Nonce: 1,
SenderPublicKey: "036a16b1b5d4a7edb2e1055d3adcf13a71d380d33...",
Fee: 10000000,
Amount: 200000000,
RecipientId: "0x21a9460c9a92fe61498d7f4623c8cd7bc3831e47",
Signature: "3045022100df8b7e9b8a4a7b6dbf...",
}
Type | Name | Required | Description |
---|---|---|---|
*Transaction | transaction | Yes | Transaction object to populate with header data. |
Return Value
This method deserializes the header of the transaction and returns the offset for further deserialization.
offset := deserializeHeader(transaction)
>> 59
Deserialize transaction type-specific data
func deserializeTypeSpecific(typeSpecificOffset int, transaction *Transaction) *Transaction
Parameters
Type | Name | Required | Description |
---|---|---|---|
int | typeSpecificOffset | Yes | Offset to start reading type-specific data from. |
*Transaction | transaction | Yes | Transaction object to populate with type-specific data. |
Return Value
This method deserializes the type-specific data of the transaction based on its type and updates the transaction object.
transaction = deserializeTypeSpecific(offset, transaction)
>> &Transaction{...}
Deserialize common transaction data
func deserializeCommon(transaction *Transaction) *Transaction
Parameters
Type | Name | Required | Description |
---|---|---|---|
*Transaction | transaction | Yes | Transaction object to populate with common data. |
Return Value
This method deserializes the common data of the transaction and updates the transaction object.
transaction = deserializeCommon(transaction)
>> &Transaction{...}
Deserialize a transfer transaction
func deserializeTransfer(typeSpecificOffset int, transaction *Transaction) *Transaction
Parameters
Type | Name | Required | Description |
---|---|---|---|
int | typeSpecificOffset | Yes | Offset to start reading type-specific data from. |
*Transaction | transaction | Yes | Transaction object to populate with transfer data. |
Return Value
This method deserializes a transfer transaction from the provided offset and updates the transaction object.
transaction = deserializeTransfer(offset, transaction)
>> &Transaction{
Amount: 100000000,
RecipientId: "0x1234567890abcdef...",
}
Deserialize a vote transaction
func deserializeVote(typeSpecificOffset int, transaction *Transaction) *Transaction
Parameters
Type | Name | Required | Description |
---|---|---|---|
int | typeSpecificOffset | Yes | Offset to start reading type-specific data from. |
*Transaction | transaction | Yes | Transaction object to populate with vote data. |
Return Value
This method deserializes a vote transaction from the provided offset and updates the transaction object.
transaction = deserializeVote(offset, transaction)
>> &Transaction{
Asset: &TransactionAsset{
Votes: []string{"+036a16b1b5d4a7edb2e1055d3adcf13a71d380d33..."},
Unvotes: []string{"-036a16b1b5d4a7edb2e1055d3adcf13a71d380d33..."},
},
}
Deserialize a validator registration transaction
func deserializeValidatorRegistration(typeSpecificOffset int, transaction *Transaction) *Transaction
Parameters
Type | Name | Required | Description |
---|---|---|---|
int | typeSpecificOffset | Yes | Offset to start reading type-specific data from. |
*Transaction | transaction | Yes | Transaction object to populate with validator registration data. |
Return Value
This method deserializes a validator registration transaction from the provided offset and updates the transaction object.
transaction = deserializeValidatorRegistration(offset, transaction)
>> &Transaction{
Asset: &TransactionAsset{
Validator: &ValidatorAsset{
ValidatorPublicKey: "abcdef1234567890abcdef1234567890...",
},
},
}
Deserialize a multi-signature registration transaction
func deserializeMultiSignatureRegistration(typeSpecificOffset int, transaction *Transaction) *Transaction
Parameters
Type | Name | Required | Description |
---|---|---|---|
int | typeSpecificOffset | Yes | Offset to start reading type-specific data from. |
*Transaction | transaction | Yes | Transaction object to populate with multi-signature registration data. |
Return Value
This method deserializes a multi-signature registration transaction from the provided offset and updates the transaction object.
transaction = deserializeMultiSignatureRegistration(offset, transaction)
>> &Transaction{
Asset: &TransactionAsset{
MultiSignature: &MultiSignatureRegistrationAsset{
Min: 2,
PublicKeys: []string{"036a16b1b5d4a7edb2e1055d3adcf13a71d380d33...", "02a123b4c5d6e7f8g9h0i1j2k3l4m5n6o7p8q9r0..."},
},
},
}
Deserialize a multi-payment transaction
func deserializeMultiPayment(typeSpecificOffset int, transaction *Transaction) *Transaction
Parameters
Type | Name | Required | Description |
---|---|---|---|
int | typeSpecificOffset | Yes | Offset to start reading type-specific data from. |
*Transaction | transaction | Yes | Transaction object to populate with multi-payment data. |
Return Value
This method deserializes a multi-payment transaction from the provided offset and updates the transaction object.
transaction = deserializeMultiPayment(offset, transaction)
>> &Transaction{
Asset: &TransactionAsset{
Payments: []*MultiPaymentAsset{
{
Amount: 50000000,
RecipientId: "0xabcdef1234567890abcdef1234567890...",
},
{
Amount: 100000000,
RecipientId: "0x1234567890abcdef1234567890abcdef...",
},
},
},
}
Deserialize a validator resignation transaction
func deserializeValidatorResignation(typeSpecificOffset int, transaction *Transaction) *Transaction
Parameters
Type | Name | Required | Description |
---|---|---|---|
int | typeSpecificOffset | Yes | Offset to start reading type-specific data from. |
*Transaction | transaction | Yes | Transaction object to populate with validator resignation data. |
Return Value
This method deserializes a validator resignation transaction from the provided offset and updates the transaction object.
transaction = deserializeValidatorResignation
(offset, transaction)
>> &Transaction{...}
Deserialize a username registration transaction
func deserializeUsernameRegistration(typeSpecificOffset int, transaction *Transaction) *Transaction
Parameters
Type | Name | Required | Description |
---|---|---|---|
int | typeSpecificOffset | Yes | Offset to start reading type-specific data from. |
*Transaction | transaction | Yes | Transaction object to populate with username registration data. |
Return Value
This method deserializes a username registration transaction from the provided offset and updates the transaction object.
transaction = deserializeUsernameRegistration(offset, transaction)
>> &Transaction{
Asset: &TransactionAsset{
Username: &UsernameAsset{
Username: "myUsername",
},
},
}
Deserialize a username resignation transaction
func deserializeUsernameResignation(typeSpecificOffset int, transaction *Transaction) *Transaction
Parameters
Type | Name | Required | Description |
---|---|---|---|
int | typeSpecificOffset | Yes | Offset to start reading type-specific data from. |
*Transaction | transaction | Yes | Transaction object to populate with username resignation data. |
Return Value
This method deserializes a username resignation transaction from the provided offset and updates the transaction object.
transaction = deserializeUsernameResignation(offset, transaction)
>> &Transaction{...}
Message
Type | Name | Required | Description |
---|---|---|---|
string | message | Yes | The message to be signed. |
string | passphrase | Yes | The passphrase to sign the message with. |
Return Value
This function returns a `Message` object containing the signed message, public key, and signature.
signedMessage, _ := SignMessage("Hello, Ark!", "super secret passphrase")
>> &Message{
Message: "Hello, Ark!",
PublicKey: "03f35d6b51212d0bf3467f57402414f13b46c7...",
Signature: "3045022100f0d1a7b5d10255d9b7c4...",
}
Type | Name | Required | Description |
---|---|---|---|
*Message | message | Yes | The message object containing the message, public key, and signature. |
Return Value
This method verifies the signed message. Returns `true` if the message is verified successfully, otherwise returns `false` and an error.
isVerified, _ := signedMessage.Verify()
>> true
This method returns a map representation of the message object, including the public key, message, and signature.
messageMap := signedMessage.ToMap()
>> map[string]interface{}{
"message": "Hello, Ark!",
"publickey": "03f35d6b51212d0bf3467f57402414f13b46c7...",
"signature": "3045022100f0d1a7b5d10255d9b7c4...",
}
This method returns a JSON string representation of the message object, including the public key, message, and signature.
messageJson, _ := signedMessage.ToJson()
>> '{"message":"Hello, Ark!","publickey":"03f35d6b51212d0bf3467f57402414f13b46c7...","signature":"3045022100f0d1a7b5d10255d9b7c4..."}'
Slot
This function returns the time difference in seconds between the current time and the network start time as an integer.
timeDiff := GetTime()
>> 123456789