public function toBytes(bool $skipSignature = true, bool $skipSecondSignature = true): Buffer
    {
        $buffer = new Writer();
        $buffer->writeUInt8($this->type);
        $buffer->writeUInt32($this->timestamp);
        $buffer->writeHex($this->senderPublicKey);

        $skipRecipientId = $this->type === Types::SECOND_SIGNATURE_REGISTRATION || $this->type === Types::MULTI_SIGNATURE_REGISTRATION;
        if (isset($this->recipientId) && ! $skipRecipientId) {
            $buffer->writeHex(Base58::decodeCheck($this->recipientId)->getHex());
        } else {
            $buffer->fill(21);
        }

        if (isset($this->vendorField) && strlen($this->vendorField) <= 64) {
            $buffer->writeString($this->vendorField);
            $vendorFieldLength = strlen($this->vendorField);

            if ($vendorFieldLength < 64) {
                $buffer->fill(64 - $vendorFieldLength);
            }
        } else {
            $buffer->fill(64);
        }

        $buffer->writeUInt64($this->amount);
        $buffer->writeUInt64($this->fee);

        if (Types::SECOND_SIGNATURE_REGISTRATION === $this->type) {
            $buffer->writeHex($this->asset['signature']['publicKey']);
        }

        if (Types::DELEGATE_REGISTRATION === $this->type) {
            $buffer->writeString($this->asset['delegate']['username']);
        }

        if (Types::VOTE === $this->type) {
            $buffer->writeString(implode('', $this->asset['votes']));
        }

        if (Types::MULTI_SIGNATURE_REGISTRATION === $this->type) {
            $buffer->writeUInt8($this->asset['multisignature']['min']);
            $buffer->writeUInt8($this->asset['multisignature']['lifetime']);
            $buffer->writeString(implode('', $this->asset['multisignature']['keysgroup']));
        }

        if (! $skipSignature && $this->signature) {
            $buffer->writeHex($this->signature);
        }

        if (! $skipSecondSignature && isset($this->signSignature)) {
            $buffer->writeHex($this->signSignature);
        }

        return new Buffer($buffer->toBytes());
    }