API Documentation
Identity
Derive an address from a passphrase
public static function fromPassphrase(string $passphrase)
Parameters
Type | Name | Required | Description |
---|---|---|---|
string | passphrase | Yes | Passphrase |
Return Value
This function returns an address derived from the given passphrase as a string.
use ArkEcosystem\Crypto\Identities\Address;
$address = Address::fromPassphrase('super secret passphrase');
>> '0x2289577F3784788784226Eb41E9B0ca9705C7C37'
Derive an address from a public key
public static function fromPublicKey(string $publicKey)
Parameters
Type | Name | Required | Description |
---|---|---|---|
string | publicKey | Yes | Public key |
Return Value
This function returns an address derived from the given public key as a string.
use ArkEcosystem\Crypto\Identities\Address;
$address = Address::fromPublicKey('023efc1da7f315f3c533a4080e491f32cd4219731cef008976c3876539e1f192d3');
>> '0x6F0182a0cc707b055322CcF6d4CB6a5Aff1aEb22'
Derive an address from a private key
public static function fromPrivateKey(EccPrivateKey $privateKey)
Parameters
Type | Name | Required | Description |
---|---|---|---|
EccPrivateKey | privateKey | Yes | Private key |
Return Value
This function returns an address derived from the given private key as a string.
use ArkEcosystem\Crypto\Identities\PrivateKey;
$privateKey = PrivateKey::fromPassphrase('this is a top secret passphrase');
$address = Address::fromPrivateKey($privateKey);
>> '0xb0FF9213f7226bBB72b84dE16af86e56f1f38B01'
Type | Name | Required | Description |
---|---|---|---|
string | address | Yes | Address to validate |
Return Value
This method returns a boolean indicating the validity of the address.
use ArkEcosystem\Crypto\Identities\Address;
$isValid = Address::validate('0x2289577F3784788784226Eb41E9B0ca9705C7C37');
>> true
Derive a private key from a passphrase
public static function fromPassphrase(string $passphrase)
Parameters
Type | Name | Required | Description |
---|---|---|---|
string | passphrase | Yes | Passphrase |
Return Value
This method returns a PrivateKey object derived from the given passphrase.
use ArkEcosystem\Crypto\Identities\PrivateKey;
$privateKey = PrivateKey::fromPassphrase('this is a top secret passphrase');
>> PrivateKey
Type | Name | Required | Description |
---|---|---|---|
string | privateKey | Yes | Hexadecimal representation of the private key |
Return Value
This method returns a PrivateKey object derived from a hex string.
use ArkEcosystem\Crypto\Identities\PrivateKey;
$privateKey = PrivateKey::fromHex('d8839c2432bfd0a67ef10a804ba991eabba19f154a3d707917681d45822a5712');
>> PrivateKey
Type | Name | Required | Description |
---|---|---|---|
string | wif | Yes | Hexadecimal representation of the WIF string |
Return Value
This method returns a PrivateKey object derived from a WIF string.
use ArkEcosystem\Crypto\Identities\PrivateKey;
$privateKey = PrivateKey::fromWif('UZYnRZ8qpeQWTLeCNzw93guWSdKLmr2vHEWGG4sNv7TJofL7TZvy');
>> PrivateKey
Signs a message using the private key
public function sign(BufferInterface $message): CompactSignature
Parameters
Type | Name | Required | Description |
---|---|---|---|
string | message | Yes | Message to sign in hex (without 0x) |
Return Value
This method signs a message using the private key.
use ArkEcosystem\Crypto\Identities\PrivateKey;
$privateKey = PrivateKey::fromPassphrase('this is a top secret passphrase');
$signature = $privateKey->sign(new Buffer('Hello World'));
>> CompactSignature
Derive a public key from a passphrase
public static function fromPassphrase(string $passphrase): PublicKey
Parameters
Type | Name | Required | Description |
---|---|---|---|
string | passphrase | Yes | Passphrase |
Return Value
This function returns a public key instance object derived from the given passphrase.
use ArkEcosystem\Crypto\Identities\PublicKey;
$publicKey = PublicKey::fromPassphrase('this is a top secret passphrase');
>> PublicKey
Type | Name | Required | Description |
---|---|---|---|
BitWaspBuffertoolsBufferInterface|string | publicKey | Yes | Public key in hex string or Buffer format |
Return Value
This function returns a PublicKey object created from the given hex string.
use ArkEcosystem\Crypto\Identities\PublicKey;
$publicKey = PublicKey::fromHex('034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192');
>> PublicKey
Recover a public key from a signature
public static function recover(BufferInterface $message, CompactSignatureInterface $signature): self
Parameters
Type | Name | Required | Description |
---|---|---|---|
BufferInterface | message | Yes | Message to use to recover |
CompactSignatureInterface | signature | Yes | Signature to use to recover |
Return Value
This function returns a PublicKey object recovered from the given signature and message.
use ArkEcosystem\Crypto\Identities\PublicKey;
$publicKey = PublicKey::recover($message, $signature);
>> PublicKey
Derive a WIF from a passphrase
public static function fromPassphrase(string $passphrase, AbstractNetwork $network = null)
Parameters
Type | Name | Required | Description |
---|---|---|---|
string | passphrase | Yes | Passphrase |
AbstractNetwork | network | No | Network WIF |
Return Value
This method returns a WIF in string format.
use ArkEcosystem\Crypto\Identities\PrivateKey;
$privateKey = PrivateKey::fromWif('validWif');
>> EcPrivateKey
Network
Set the network you want to use in the crypto library
public static function set(AbstractNetwork $network)
Parameters
Type | Name | Required | Description |
---|---|---|---|
AbstractNetwork | network | Yes | Network object (Testnet, Mainnet, etc) |
Return Value
This method returns void.
use ArkEcosystem\Crypto\Configuration\Network;
use ArkEcosystem\Crypto\Networks\Testnet;
Network::set(new Testnet());
>> void
// Custom network example
use ArkEcosystem\Crypto\Configuration\Network;
use ArkEcosystem\Crypto\Networks\AbstractNetwork;
class CustomNetwork extends AbstractNetwork {
...
}
Network::set(new CustomNetwork());
>> void
This function returns the current network.
use ArkEcosystem\Crypto\Configuration\Network;
$network = Network::get();
>> AbstractNetwork
This method returns the chain ID as an integer.
use ArkEcosystem\Crypto\Networks\Testnet;
(new Testnet())->chainId();
>> 10000
This method returns the epoch time in string format.
use ArkEcosystem\Crypto\Networks\Testnet;
(new Testnet())->epoch();
>> '2017-03-21T13:00:00.000Z'
This method returns the WIF in hexadecimal string format.
use ArkEcosystem\Crypto\Networks\Testnet;
(new Testnet())->wif();
>> 'ba'
Transactions
For full examples of using the Builders to create transactions, please have a look at the Examples page.
Type | Name | Required | Description |
---|---|---|---|
?array | data | No | Optional transaction data |
Return Value
This method returns a new transaction instance in self format.
use ArkEcosystem\Crypto\Transactions\Builder\TransferBuilder;
// Using TransferBuilder as an example of AbstractTransactionBuilder
$transaction = TransferBuilder::new();
>> TransferBuilder
Return Value
This method returns the string representation of the transaction.
use ArkEcosystem\Crypto\Transactions\Builder\TransferBuilder;
// Using TransferBuilder as an example of AbstractTransactionBuilder
echo TransferBuilder::new()->__toString();
>> '{"gasPrice":"5000000000","network":30,"gasLimit":1000000,"nonce":"1","senderPublicKey":"","value":"0","data":""}'
Type | Name | Required | Description |
---|---|---|---|
int | string | gasLimit | Yes | Gas limit for the transaction |
Return Value
This method returns the transaction instance in self format.
use ArkEcosystem\Crypto\Transactions\Builder\TransferBuilder;
// Using TransferBuilder as an example of AbstractTransactionBuilder
$transaction = TransferBuilder::new()->gasLimit(1000000);
>> TransferBuilder
Type | Name | Required | Description |
---|---|---|---|
string | to | Yes | Recipient address |
Return Value
This method returns the transaction instance in self format.
use ArkEcosystem\Crypto\Transactions\Builder\TransferBuilder;
// Using TransferBuilder as an example of AbstractTransactionBuilder
$transaction = TransferBuilder::new()->to('0x6F0182a0cc707b055322CcF6d4CB6a5Aff1aEb22');
>> TransferBuilder
Set the gas price for the transaction
public function gasPrice(int | string $gasPrice): static
Parameters
Type | Name | Required | Description |
---|---|---|---|
int | string | gasPrice | Yes | Gas price for the transaction |
Return Value
This method returns the transaction instance in self format.
use ArkEcosystem\Crypto\Transactions\Builder\TransferBuilder;
// Using TransferBuilder as an example of AbstractTransactionBuilder
$transaction = TransferBuilder::new()->gasPrice(5000000000);
>> TransferBuilder
Type | Name | Required | Description |
---|---|---|---|
string | nonce | Yes | Nonce for the transaction |
Return Value
This method returns the transaction instance in self format.
use ArkEcosystem\Crypto\Transactions\Builder\TransferBuilder;
// Using TransferBuilder as an example of AbstractTransactionBuilder
$transaction = TransferBuilder::new()->nonce('1');
>> TransferBuilder
Type | Name | Required | Description |
---|---|---|---|
int | network | Yes | Network identifier (e.g., Mainnet, Testnet) |
Return Value
This method returns the transaction instance in self format.
use ArkEcosystem\Crypto\Transactions\Builder\TransferBuilder;
// Using TransferBuilder as an example of AbstractTransactionBuilder
$transaction = TransferBuilder::new()->network(23);
>> TransferBuilder
Sign the transaction using the given passphrase
public function sign(string $passphrase): static
Parameters
Type | Name | Required | Description |
---|---|---|---|
string | passphrase | Yes | Passphrase for signing the transaction |
Return Value
This method signs the transaction using the provided passphrase and returns the builder instance.
use ArkEcosystem\Crypto\Transactions\Builder\TransferBuilder;
// Using TransferBuilder as an example of AbstractTransactionBuilder
$transaction = TransferBuilder::new()->sign('this is a top secret passphrase');
>> TransferBuilder
Sign the transaction with a second signature (only for legacy addresses)
public function legacySecondSign(string $passphrase, string $secondPasphrase): static
Parameters
Type | Name | Required | Description |
---|---|---|---|
string | passphrase | Yes | Passphrase for signing the transaction |
string | secondPassphrase | Yes | Second Passphrase for signing the transaction |
Return Value
This method signs the transaction using the provided passphrases and returns the builder instance.
use ArkEcosystem\Crypto\Transactions\Builder\TransferBuilder;
// Using TransferBuilder as an example of AbstractTransactionBuilder
$transaction = TransferBuilder::new()->legacySecondSign('this is a top secret passphrase',this is a top secret second passphrase');
>> TransferBuilder
This method returns the validity of the transaction as a boolean.
use ArkEcosystem\Crypto\Transactions\Builder\TransferBuilder;
// Using TransferBuilder as an example of AbstractTransactionBuilder
$isValid = TransferBuilder::new()
->to('0x6F0182a0cc707b055322CcF6d4CB6a5Aff1aEb22')
->sign('this is a top secret passphrase')
->verify();
>> true
This method returns the transaction data as an array.
use ArkEcosystem\Crypto\Transactions\Builder\TransferBuilder;
// Using TransferBuilder as an example of AbstractTransactionBuilder
$data = TransferBuilder::new()->toArray();
>> [
"gasPrice" => "5000000000",
"network" => 30,
"gasLimit" => 1000000,
"nonce" => 1,
"senderPublicKey" => "",
"value" => "0",
"data" => "",
]
This method returns the JSON representation of the transaction as a string.
use ArkEcosystem\Crypto\Transactions\Builder\TransferBuilder;
// Using TransferBuilder as an example of AbstractTransactionBuilder
$json = TransferBuilder::new()->toJson();
>> '{"value": "0", ..., "data": ""}'
Inherits from:AbstractTransactionBuilder
Type | Name | Required | Description |
---|---|---|---|
string | payload | Yes | EVM code in hex format (without `0x` prefix) |
Return Value
Returns the transaction instance with the payload set.
use ArkEcosystem\Crypto\Transactions\Builder\EvmCallBuilder;
$transaction = EvmCallBuilder::new()->payload('yourHexPayload');
>> EvmCallBuilder
Inherits from:AbstractTransactionBuilder
Add recipient to the transaction
public function pay(string $address, BigDecimal $value): self
Parameters
Type | Name | Required | Description |
---|---|---|---|
string | address | Yes | Address to recipient |
BigDecimal | value | Yes | Amount to send to recipient |
Return Value
This method adds a recipient to the transaction and returns the builder instance.
use ArkEcosystem\Crypto\Transactions\Builder\MultipaymentBuilder;
$transaction = MultipaymentBuilder::new()->pay('0x512F366D524157BcF734546eB29a6d687B762255', BigDecimal::of('100000'));
>> MultipaymentBuilder
Inherits from:AbstractTransactionBuilder
Type | Name | Required | Description |
---|---|---|---|
string | value | Yes | Amount to transfer in wei |
Return Value
This method returns the transaction instance with the value set.
use ArkEcosystem\Crypto\Transactions\Builder\TransferBuilder;
$transaction = TransferBuilder::new()->value('1000000000000000000');
>> TransferBuilder
Inherits from:AbstractTransactionBuilder
Set the validator BLS public key
public function validatorPublicKey(string $validatorPublicKey): self
Parameters
Type | Name | Required | Description |
---|---|---|---|
string | validatorPublicKey | Yes | Validator BLS public key to register |
Return Value
This method returns the transaction instance with the validator public key set.
use ArkEcosystem\Crypto\Transactions\Builder\ValidatorRegistrationBuilder;
$transaction = ValidatorRegistrationBuilder::new()->validatorPublicKey('954f46d6097a1d314e900e66e11e0dad0a57cd03e04ec99f0dedd1c765dcb11e6d7fa02e22cf40f9ee23d9cc1c0624bd');
>> ValidatorRegistrationBuilder
Type | Name | Required | Description |
---|---|---|---|
string | value | Yes | Amount to lock in wei |
Return Value
This method returns the transaction instance with the value set.
use ArkEcosystem\Crypto\Transactions\Builder\ValidatorRegistrationBuilder;
$transaction = ValidatorRegistrationBuilder::new()->value('250000000000000000000');
>> ValidatorRegistrationBuilder
Inherits from:AbstractTransactionBuilder
Inherits from:AbstractTransactionBuilder
Type | Name | Required | Description |
---|---|---|---|
string | username | Yes | Username to register |
Return Value
This method returns the transaction instance with the username set.
use ArkEcosystem\Crypto\Transactions\Builder\UsernameRegistrationBuilder;
$transaction = UsernameRegistrationBuilder::new()->username('myusername');
>> UsernameRegistrationBuilder
Inherits from:AbstractTransactionBuilder
Type | Name | Required | Description |
---|---|---|---|
string | username | Yes | Username to register |
Return Value
This method returns the transaction instance with the username set.
use ArkEcosystem\Crypto\Transactions\Builder\UsernameRegistrationBuilder;
$transaction = UsernameRegistrationBuilder::new()->username('myusername');
>> UsernameRegistrationBuilder
Inherits from:AbstractTransactionBuilder
Inherits from:AbstractTransactionBuilder
Type | Name | Required | Description |
---|---|---|---|
string | vote | Yes | Public key of the validator to vote for |
Return Value
This method returns the transaction instance with the vote set.
use ArkEcosystem\Crypto\Transactions\Builder\VoteBuilder;
$transaction = VoteBuilder::new()->vote('0xC3bBE9B1CeE1ff85Ad72b87414B0E9B7F2366763');
>> VoteBuilder
Inherits from:AbstractTransactionBuilder
It is recommended to use the Transaction Builders instead of the AbstractTransaction class directly. You can also access the underlying transaction
property of the Builder to work with the AbstractTransaction instance, e.g. TransferBuilder::new()->transaction
.
Type | Name | Required | Description |
---|---|---|---|
?array | data | No | Optional transaction data |
Return Value
This method initializes a new transaction instance.
use ArkEcosystem\Crypto\Transactions\Types\Transfer;
// Using Transfer as an example of AbstractTransaction
$transaction = new Transfer();
>> Transfer
This method returns the payload of the transaction as a string.
use ArkEcosystem\Crypto\Transactions\Types\Transfer;
use ArkEcosystem\Crypto\Transactions\Types\Vote;
use ArkEcosystem\Crypto\Utils\AbiEncoder;
$payload = (new Transfer())->getPayload();
>> ''
$encoded = (new AbiEncoder())->encodeFunctionCall('vote', ['0xC3bBE9B1CeE1ff85Ad72b87414B0E9B7F2366763']);
$payload = (new Vote(['data' => $encoded]))->getPayload();
>> '0x6dd7d8ea000000000000000000000000c3bbe9b1cee1ff85ad72b87414b0e9b7f2366763'
Sign the transaction using the given private key
public function sign(PrivateKey $keys): static
Parameters
Type | Name | Required | Description |
---|---|---|---|
PrivateKey | keys | Yes | Private key for signing |
Return Value
This method signs the transaction and returns the transaction instance.
use ArkEcosystem\Crypto\Transactions\Types\Transfer;
use ArkEcosystem\Crypto\Identities\PrivateKey;
// Using Transfer as an example of AbstractTransaction
(new Transfer([
'value' => '1',
'nonce' => 1,
'to' => '0x6F0182a0cc707b055322CcF6d4CB6a5Aff1aEb22',
'gasPrice' => 5000000000,
'gas' => 21000
]))->sign(PrivateKey::fromPassphrase('this is a top secret passphrase'))
>> Transfer
This method recovers the sender's public key and address from the transaction signature.
use ArkEcosystem\Crypto\Transactions\Types\Transfer;
use ArkEcosystem\Crypto\Identities\PrivateKey;
// Using Transfer as an example of AbstractTransaction
$transfer = (new Transfer([
'value' => '1',
'nonce' => 1,
'to' => '0x6F0182a0cc707b055322CcF6d4CB6a5Aff1aEb22',
'gasPrice' => 5000000000,
'gas' => 21000
]))->sign(PrivateKey::fromPassphrase('this is a top secret passphrase'));
$transfer->recoverSender();
$transfer->toJson();
>> '{..., "to":"0x6F0182a0cc707b055322CcF6d4CB6a5Aff1aEb22"}'
This method verifies the transaction signature and returns a boolean indicating validity.
use ArkEcosystem\Crypto\Transactions\Types\Transfer;
use ArkEcosystem\Crypto\Identities\PrivateKey;
// Using Transfer as an example of AbstractTransaction
$transfer = (new Transfer([
'value' => '1',
'nonce' => 1,
'to' => '0x6F0182a0cc707b055322CcF6d4CB6a5Aff1aEb22',
'gasPrice' => 5000000000,
'gas' => 21000
]))->sign(PrivateKey::fromPassphrase('this is a top secret passphrase'));
$transfer->verify();
>> true
Type | Name | Required | Description |
---|---|---|---|
array | options | No | Serialization options |
Return Value
This method serializes the transaction and returns it as a Buffer.
use ArkEcosystem\Crypto\Transactions\Types\Transfer;
// Using Transfer as an example of AbstractTransaction
$serialized = (new Transfer([
'value' => '1',
'nonce' => 1,
'to' => '0x6F0182a0cc707b055322CcF6d4CB6a5Aff1aEb22',
'gasPrice' => 5000000000,
'gas' => 21000
]))->serialize();
>> Buffer
Get the hash for the transaction
public function hash(bool $skipSignature = false): BufferInterface
Parameters
Type | Name | Required | Description |
---|---|---|---|
bool | skipSignature | No | Serialization options |
Return Value
This method generates the hash for the transaction and returns it as a string.
use ArkEcosystem\Crypto\Transactions\Types\Transfer;
// Using Transfer as an example of AbstractTransaction
$hash = (new Transfer([
'value' => '1',
'nonce' => 1,
'to' => '0x6F0182a0cc707b055322CcF6d4CB6a5Aff1aEb22',
'gasPrice' => 5000000000,
'gas' => 21000,
])).hash();
>> string
This method refreshes the payload data of the transaction and returns the transaction instance.
use ArkEcosystem\Crypto\Transactions\Types\Transfer;
// Using Transfer as an example of AbstractTransaction
$transaction = (new Transfer({
'value' => '1',
'nonce' => 1,
'to' => '0x6F0182a0cc707b055322CcF6d4CB6a5Aff1aEb22',
'gasPrice' => 5000000000,
'gas' => 21000,
})).refreshPayloadData();
>> Transfer
This method returns the transaction data as an array.
use ArkEcosystem\Crypto\Transactions\Types\Transfer;
// Using Transfer as an example of AbstractTransaction
$array =(new Transfer([
'value' => '1',
'nonce' => 1,
'to' => '0x6F0182a0cc707b055322CcF6d4CB6a5Aff1aEb22',
'gasPrice' => 5000000000,
'gas' => 21000
]))->toArray();
>> ["gasPrice" => ..., "gasLimit" => ...]
This method returns the JSON representation of the transaction as a string.
use ArkEcosystem\Crypto\Transactions\Types\Transfer;
// Using Transfer as an example of AbstractTransaction
$json = (new Transfer([
'value' => '1',
'nonce' => 1,
'to' => '0x6F0182a0cc707b055322CcF6d4CB6a5Aff1aEb22',
'gasPrice' => 5000000000,
'gas' => 21000
]))->toJson();
>> '{"gasPrice":..., "hash":...}'
Inherits from:AbstractTransaction
Inherits from:AbstractTransaction
Inherits from:AbstractTransaction
Inherits from:AbstractTransaction
Inherits from:AbstractTransaction
Inherits from:AbstractTransaction
Inherits from:AbstractTransaction
Inherits from:AbstractTransaction
Inherits from:AbstractTransaction
Serializer
Type | Name | Required | Description |
---|---|---|---|
AbstractTransaction | transaction | Yes | Transaction to be serialized |
Return Value
This method returns a new serializer instance.
use ArkEcosystem\Crypto\Transactions\Builder\TransferBuilder;
use ArkEcosystem\Crypto\Transactions\Serializer;
$tx = TransferBuilder::new()
->value(0)
->gasPrice(5000000000)
->gasLimit(21000)
->to('0x6F0182a0cc707b055322CcF6d4CB6a5Aff1aEb22')
->sign('this is a top secret passphrase')
->transaction;
$serializer = Serializer::new($transaction);
>> Serializer
Type | Name | Required | Description |
---|---|---|---|
array | options | No | Serialization options |
Return Value
This method serializes the transaction and returns it as a Buffer.
use ArkEcosystem\Crypto\Transactions\Builder\TransferBuilder;
use ArkEcosystem\Crypto\Transactions\Serializer;
$tx = TransferBuilder::new()
->value(0)
->gasPrice(5000000000)
->gasLimit(21000)
->to('0x6F0182a0cc707b055322CcF6d4CB6a5Aff1aEb22')
->sign('this is a top secret passphrase')
->transaction;
$serialized = (Serializer::new($tx))->serialize();
>> Buffer
Deserializer
Type | Name | Required | Description |
---|---|---|---|
string | serialized | Yes | Serialized transaction data |
Return Value
This method returns a new deserializer instance.
use ArkEcosystem\Crypto\Transactions\Builder\TransferBuilder;
use ArkEcosystem\Crypto\Transactions\Deserializer;
$tx = TransferBuilder::new()
->value(0)
->gasPrice(5000000000)
->gasLimit(21000)
->to('0x6F0182a0cc707b055322CcF6d4CB6a5Aff1aEb22')
->sign('this is a top secret passphrase')
->transaction;
$deserializer = Deserializer::new($tx->serialize()->getHex());
>> Deserializer
This method deserializes the transaction and returns an instance of AbstractTransaction.
use ArkEcosystem\Crypto\Transactions\Builder\TransferBuilder;
use ArkEcosystem\Crypto\Transactions\Deserializer;
$tx = TransferBuilder::new()
->value(0)
->gasPrice(5000000000)
->gasLimit(21000)
->to('0x6F0182a0cc707b055322CcF6d4CB6a5Aff1aEb22')
->sign('this is a top secret passphrase')
->transaction;
$transaction = Deserializer::new($tx->serialize()->getHex())->deserialize();
>> AbstractTransaction
Decode the payload of a transaction
public static function decodePayload(array $data, ContractAbiType $abiType = ContractAbiType::CONSENSUS): ?array
Parameters
Type | Name | Required | Description |
---|---|---|---|
array | data | Yes | The array containing the payload data to decode. |
ContractAbiType | abiType | No | Contract ABI Type to decode against |
Return Value
This method decodes the payload data of a transaction and returns it as an array. If decoding fails, it returns `null`.
use ArkEcosystem\Crypto\Transactions\Deserializer;
use ArkEcosystem\Crypto\Enums\ContractAbiType;
$payloadData = Deserializer::decodePayload($transactionData)
>> {'args': [...], ...}
$payloadData = Deserializer::decodePayload($transactionData, ContractAbiType::USERNAMES)
>> {'args': [...], ...}
Message
Type | Name | Required | Description |
---|---|---|---|
mixed | message | Yes | Message data (object, array, or JSON string) |
Return Value
This method returns a new message instance.
use ArkEcosystem\Crypto\Utils\Message;
$message = Message::new((object) array(
'publicKey' => '034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192',
'signature' => '0x6fc765ffd60aec43dc5eff277173006c8902c4a044712f1c10fb6ea1707b0199092235829bceb59a55a83556e44599bcc5677c3a28d8532ca72db183281a48dc1b',
'message' => 'Hello World'
));
>> Message
Sign a message using the given passphrase
public static function sign(string $message, string $passphrase)
Parameters
Type | Name | Required | Description |
---|---|---|---|
string | message | Yes | Message to sign |
string | passphrase | Yes | Passphrase for signing |
Return Value
This method signs the message and returns a new Message instance.
use ArkEcosystem\Crypto\Utils\Message;
$signedMessage = Message::sign('Hello World', 'this is a top secret passphrase');
>> Message
This method verifies the message and returns a boolean value indicating validity.
use ArkEcosystem\Crypto\Utils\Message;
$signedMessage = Message::sign('Hello World', 'this is a top secret passphrase');
$isValid = $signedMessage->verify();
>> true
This method converts the message to an array and returns it.
use ArkEcosystem\Crypto\Utils\Message;
$signedMessage = Message::sign('Hello World', 'this is a top secret passphrase');
$arrayMessage = $signedMessage->toArray();
>> [
'publicKey' => '034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192',
'signature' => '0x6fc765ffd60aec43dc5eff277173006c8902c4a044712f1c10fb6ea1707b0199092235829bceb59a55a83556e44599bcc5677c3a28d8532ca72db183281a48dc1b',
'message' => 'Hello World'
]
This method returns the string representation of the message in JSON format.
use ArkEcosystem\Crypto\Utils\Message;
$message = new Message((object) array(
'publicKey' => '034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192',
'signature' => '0x6fc765ffd60aec43dc5eff277173006c8902c4a044712f1c10fb6ea1707b0199092235829bceb59a55a83556e44599bcc5677c3a28d8532ca72db183281a48dc1b',
'message' => 'Hello World'
));
(string) $message;
>> '{"publickey":"034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192","signature":"0x6fc765ffd60aec43dc5eff277173006c8902c4a044712f1c10fb6ea1707b0199092235829bceb59a55a83556e44599bcc5677c3a28d8532ca72db183281a48dc1b","message":"Hello World"}'
This method converts the message to a JSON string and returns it.
use ArkEcosystem\Crypto\Utils\Message;
$signedMessage = Message::sign('Hello World', 'this is a top secret passphrase');
$jsonMessage = $message->toJson();
>> '{"publickey":"034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192","signature":"0x6fc765ffd60aec43dc5eff277173006c8902c4a044712f1c10fb6ea1707b0199092235829bceb59a55a83556e44599bcc5677c3a28d8532ca72db183281a48dc1b","message":"Hello World"}'
Slot
This method returns the time difference between now and the network start in int format.
use ArkEcosystem\Crypto\Utils\Slot;
$timeDiff = Slot::time();
>> 200366014
This method returns the network start epoch in int format.
use ArkEcosystem\Crypto\Utils\Slot;
$epoch = Slot::epoch();
>> 1490101200
ArgumentDecoder
Type | Name | Required | Description |
---|---|---|---|
string | bytes | Yes | The encoded bytes to be decoded |
Return Value
This method returns a new instance of the ArgumentDecoder class.
use ArkEcosystem\Crypto\Utils\Abi\ArgumentDecoder;
$decoder = new ArgumentDecoder($argument);
>> ArgumentDecoder
This method returns the decoded string.
use ArkEcosystem\Crypto\Utils\Abi\ArgumentDecoder;
$decoder = new ArgumentDecoder($argument);
$string = $decoder->decodeString();
>> string
This method returns the decoded address.
use ArkEcosystem\Crypto\Utils\Abi\ArgumentDecoder;
$decoder = new ArgumentDecoder($argument);
$address = $decoder->decodeAddress();
>> string
This method returns an unsigned integer as a string.
use ArkEcosystem\Crypto\Utils\Abi\ArgumentDecoder;
$decoder = new ArgumentDecoder($argument);
$value = $decoder->decodeUnsignedInt();
>> string
This method returns an signed integer as a string.
use ArkEcosystem\Crypto\Utils\Abi\ArgumentDecoder;
$decoder = new ArgumentDecoder($argument);
$value = $decoder->decodeSignedInt();
>> string
This method returns a boolean.
use ArkEcosystem\Crypto\Utils\Abi\ArgumentDecoder;
$decoder = new ArgumentDecoder($argument);
$value = $decoder->decodeBool();
>> bool
UnitConverter
Parse a value into the appropriate units
public static function parseUnits($value, string $unit = 'ark'): string
Parameters
Type | Name | Required | Description |
---|---|---|---|
float|int|string | value | Yes | The value to be converted |
string | unit | No | The unit to convert to (default is 'ark') |
Return Value
This method returns the value converted to the smallest unit as a string.
use ArkEcosystem\Crypto\Utils\UnitConverter;
$weiValue = UnitConverter::parseUnits(1, 'wei');
>> '1'
$gweiValue = UnitConverter::parseUnits(1, 'gwei');
>> '1000000000'
$arkValue = UnitConverter::parseUnits(1, 'ark');
>> '1000000000000000000'
$arkDecimalValue = UnitConverter::parseUnits(0.1, 'ark');
>> '100000000000000000'
Format a value from smaller units to a larger unit
public static function formatUnits(string $value, string $unit = 'ark'): float
Parameters
Type | Name | Required | Description |
---|---|---|---|
string | value | Yes | The value in the smallest unit (as a string) |
string | unit | No | The unit to format to (default is 'ark') |
Return Value
This method returns the value converted from the smallest unit to the specified unit as a float.
use ArkEcosystem\Crypto\Utils\UnitConverter;
$formattedWei = UnitConverter::formatUnits('1', 'wei');
>> 1.0
$formattedGwei = UnitConverter::formatUnits('1000000000', 'gwei');
>> 1.0
$formattedArk = UnitConverter::formatUnits('1000000000000000000', 'ark');
>> 1.0
$formattedArkDecimal = UnitConverter::formatUnits('100000000000000000', 'ark');
>> 0.1
Format a wei value to an ark value
public static function weiToArk(string | int | float $value, ?string $suffix = null): string
Parameters
Type | Name | Required | Description |
---|---|---|---|
string | int | float | value | Yes | The wei value (as a string, int or float) |
string | suffix | No | The suffix to show after the formatted value (default is null) |
Return Value
This method returns the wei value formatted as an ARK value.
use ArkEcosystem\Crypto\Utils\UnitConverter;
$formattedValue = UnitConverter::weiToArk(1, 'DARK');
>> 0.000000000000000001 DARK
$formattedValue = UnitConverter::weiToArk(1);
>> 0.000000000000000001
$formattedValue = UnitConverter::weiToArk('1000000000000000000', 'DARK');
>> 1 DARK
$formattedValue = UnitConverter::weiToArk('1000000000000000000');
>> 1
Format a gwei value to an ark value
public static function gweiToArk(string | int | float $value, ?string $suffix = null): string
Parameters
Type | Name | Required | Description |
---|---|---|---|
string | int | float | value | Yes | The gwei value (as a string, int or float) |
string | suffix | No | The suffix to show after the formatted value (default is null) |
Return Value
This method returns the gwei value formatted as an ARK value.
use ArkEcosystem\Crypto\Utils\UnitConverter;
$formattedValue = UnitConverter::gweiToArk(1, 'DARK');
>> 0.000000001 DARK
$formattedValue = UnitConverter::gweiToArk(1);
>> 0.000000001
$formattedValue = UnitConverter::gweiToArk('1000000000', 'DARK');
>> 1 DARK
$formattedValue = UnitConverter::gweiToArk('1000000000');
>> 1