10.8. Seal a draft and transfer an envelope with cURL

10.8.1. Create a draft

This example shows how to seal a draft and complete the entire transfer workflow. The following example is a cURL POST request using bearer token for request authorization. A new draft is created as a result of this request.

curl --location --request POST 'https://cargox.digital/api/v3/companies/self/inboxes/by-id/{{YOUR_INBOX_ID_HERE}}/envelopes/' \
    --header 'Authorization: Bearer qB3b6Jqb8iyTP7bLhJ7wnRqTpf2Yaa' \
     --data-raw '{"recipient_id": "{{RECIPIENT_ID_HERE}}","message": "This is a message","pay_to_collect":false}'

Request body is a FormData object. Besides the documents property, other draft fields can be set with the same request (see API reference). On success, the above cURL request returns a JSON response. Please mind the id attribute. You will need it later.

{
    "id": "086e2234-a718-43ae-9076-ee7583b84437",
    "owner_id": "c16d67b9-a9a2-4332-8301-a671bb75c199",
    "recipient_id": "04906b82-beb1-42ea-8aac-1ca8afdcdb05",
    "message": "This is a message",
    "type": "outgoing",
    "specialization_type": "standard",
    "created": "2021-04-16T12:13:53.726772Z",
    "sent": null,
    "archived": null,
    "delivered": null,
    "action_performed_by_id": null,
    "action_performed_by": null,
    "action_performed_by_company_id": null,
    "action_performed_by_company": null,
    "sealed": false,
    "can_be_sealed": false,
    "is_draft": true,
    "sender_inbox_id": null,
    "sender": null,
    "delivered_envelope_opened": false,
    "delivery_status": null,
    "can_be_archived": false,
    "can_be_unarchived": false,
    "read_by_user": false,
    "attachments": [],
    "delivered_envelope_id": null,
    "failed_delivery_envelope_id": null,
    "failed_outgoing_id": null,
    "document_token_transactions": [],
    "pay_to_collect": false,
    "pay_to_collect_response": 0,
    "meta_data": {},
    "credits_spent_amount": null,
    "is_first_acid_filing": false
}

10.8.2. Add documents to draft

To add documents to the draft please refer to the documentation chapter on Uploading documents to existing draft with cURL

10.8.3. Seal the draft

When documents are attached to a draft we can seal it.

curl --location --request POST 'https://cargox.digital/api/v3/companies/self/inboxes/by-id/{{YOUR_INBOX_ID_HERE}}/envelopes/by-id/{{YOUR_ENVELOPE_ID_HERE}}' \
    --header 'Authorization: Bearer qB3b6Jqb8iyTP7bLhJ7wnRqTpf2Yaa' \
     --data-raw '{"sealed":true}'

10.8.4. Fetch the transactions

In order to transfer the envelope we need to fetch the transactions, sign them with the appropriate blockchain key and send them back to the envelope.

To get the transactions use the following call - make sure you enter the appropriate ethereum_address (this is the public address of the blockchain key that will be used to sign the transfers):

curl --location --request POST 'https://cargox.digital/api/v3/companies/self/inboxes/by-id/{{YOUR_INBOX_ID_HERE}}/envelopes/by-id/{{YOUR_ENVELOPE_ID_HERE}}/workflow/' \
    --header 'Authorization: Bearer qB3b6Jqb8iyTP7bLhJ7wnRqTpf2Yaa' \
     --data-raw '{"action":"generate_issue_hash","ethereum_address":"{{YOUR_BLOCKCHAIN_KEY_PUBLIC_ADDRESS}}"}'

The result is a JSON document with the transaction details (one for each document in the draft - there are two in this example):

[
    {
        "document_token_id":"75c6e24c-1639-4ffa-9741-2662c85e9ac5",
        "relayed_transaction":{
            "hash":"0x63a4e9ba2f2b0d3bb9b9ccdd81940255da098871efc7ad6c0bffa38fb777b2fd",
            "relay_nonce":1,
            "recipient":"0xc8e04f362dB54e3FFeE14fC173f231B1A09DE851",
            "relayed_for":"0x3154F1709accF77147DF12C7AE07B307269388ef",
            "transaction_data":"0x3266df5b00000000000000000000000088989054fde4c610c42a20cdc256ba6d8276f7a20000000000000000000000000000000075c6e24c16394ffa97412662c85e9ac5656c97fb4af2522b4459effe1e7b424b824397a19b77cc9ce1a8ff5b1970f7b000000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000020000000000000000000000000795e6c852b579e8fb396b9d0e441d63d30fd338b0000000000000000000000000000000000000000000000000000000000000001"
        }
    },
    {
        "document_token_id":"b8dd76af-2dac-461a-b75c-030575d52bad",
        "relayed_transaction":{
            "hash":"0xe5e4394c74d55c1e9cc3096be9bb1a01f3881e6dd4b6a879324bc8ed16b76f00",
            "relay_nonce":2,
            "recipient":"0xc8e04f362dB54e3FFeE14fC173f231B1A09DE851",
            "relayed_for":"0x3154F1709accF77147DF12C7AE07B307269388ef",
            "transaction_data":"0x3266df5b00000000000000000000000088989054fde4c610c42a20cdc256ba6d8276f7a200000000000000000000000000000000b8dd76af2dac461ab75c030575d52bad168237474b53735eec9f9522ef080aca1100e08f320f38e12e21863fbdc3816300000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000020000000000000000000000000cf06ec4f5f4d8c4fedd2f5484448ef0e5709520b0000000000000000000000000000000000000000000000000000000000000001"
        }
    }
]

10.8.5. Sign the transactions

Make sure to cryptographically sign the hash of the transaction and not the transaction_data.

Here is a JavaScript example of doing so:

The following command is used to invoke the private key container (e.g. a hardware wallet, MetaMask or in-memory private key):

  • JavaScript

    web3.eth.personal.sign(
        response[0]['relayed_transaction']['hash'],
        accounts[0],
        function (e, signature) { ... }
    )
    

Please refer to any of the examples on how to sign the hash.

10.8.6. Send the signed transactions

Send back the signed transactions:

curl --location --request POST 'https://cargox.digital/api/v3/companies/self/inboxes/by-id/{{YOUR_INBOX_ID_HERE}}/envelopes/by-id/{{YOUR_ENVELOPE_ID_HERE}}/workflow/' \
    --header 'Authorization: Bearer qB3b6Jqb8iyTP7bLhJ7wnRqTpf2Yaa' \
    --data-raw '{"action":"issue","data":[{"relayed_transaction":{"hash":"0x63a4e9ba2f2b0d3bb9b9ccdd81940255da098871efc7ad6c0bffa38fb777b2fd","relay_nonce":1,"recipient":"0xc8e04f362dB54e3FFeE14fC173f231B1A09DE851","relayed_for":"0x3154F1709accF77147DF12C7AE07B307269388ef","transaction_data":"0x3266df5b00000000000000000000000088989054fde4c610c42a20cdc256ba6d8276f7a20000000000000000000000000000000075c6e24c16394ffa97412662c85e9ac5656c97fb4af2522b4459effe1e7b424b824397a19b77cc9ce1a8ff5b1970f7b000000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000020000000000000000000000000795e6c852b579e8fb396b9d0e441d63d30fd338b0000000000000000000000000000000000000000000000000000000000000001","signature":"0x4facda7cdac8f808466765674fa9b4d23d7dde9bce63d064593a737ec2c210bd589edf786a3c6ea9a7233da985e4b7d822275ad625e085f51e9df925a7b38cb01c"},"document_token_id":"75c6e24c-1639-4ffa-9741-2662c85e9ac5"},{"relayed_transaction":{"hash":"0xe5e4394c74d55c1e9cc3096be9bb1a01f3881e6dd4b6a879324bc8ed16b76f00","relay_nonce":2,"recipient":"0xc8e04f362dB54e3FFeE14fC173f231B1A09DE851","relayed_for":"0x3154F1709accF77147DF12C7AE07B307269388ef","transaction_data":"0x3266df5b00000000000000000000000088989054fde4c610c42a20cdc256ba6d8276f7a200000000000000000000000000000000b8dd76af2dac461ab75c030575d52bad168237474b53735eec9f9522ef080aca1100e08f320f38e12e21863fbdc3816300000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000020000000000000000000000000cf06ec4f5f4d8c4fedd2f5484448ef0e5709520b0000000000000000000000000000000000000000000000000000000000000001","signature":"0x5ed416cc48673d0ed3e7b5cecc30563c4b0ff9dce4915ce96c9b87426787de5245d55a065512e7fd1bf1a18f183992d5164a73762cd43f73a88e13480a5a7e211c"},"document_token_id":"b8dd76af-2dac-461a-b75c-030575d52bad"}]}'

Here is the data payload formatted for easier inspection:

[
    {
        "relayed_transaction":{
            "hash":"0x63a4e9ba2f2b0d3bb9b9ccdd81940255da098871efc7ad6c0bffa38fb777b2fd",
            "relay_nonce":1,
            "recipient":"0xc8e04f362dB54e3FFeE14fC173f231B1A09DE851",
            "relayed_for":"0x3154F1709accF77147DF12C7AE07B307269388ef",
            "transaction_data":"0x3266df5b00000000000000000000000088989054fde4c610c42a20cdc256ba6d8276f7a20000000000000000000000000000000075c6e24c16394ffa97412662c85e9ac5656c97fb4af2522b4459effe1e7b424b824397a19b77cc9ce1a8ff5b1970f7b000000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000020000000000000000000000000795e6c852b579e8fb396b9d0e441d63d30fd338b0000000000000000000000000000000000000000000000000000000000000001",
            "signature":"0x4facda7cdac8f808466765674fa9b4d23d7dde9bce63d064593a737ec2c210bd589edf786a3c6ea9a7233da985e4b7d822275ad625e085f51e9df925a7b38cb01c"
        },
        "document_token_id":"75c6e24c-1639-4ffa-9741-2662c85e9ac5"
    },
    {
        "relayed_transaction":{
            "hash":"0xe5e4394c74d55c1e9cc3096be9bb1a01f3881e6dd4b6a879324bc8ed16b76f00",
            "relay_nonce":2,
            "recipient":"0xc8e04f362dB54e3FFeE14fC173f231B1A09DE851",
            "relayed_for":"0x3154F1709accF77147DF12C7AE07B307269388ef",
            "transaction_data":"0x3266df5b00000000000000000000000088989054fde4c610c42a20cdc256ba6d8276f7a200000000000000000000000000000000b8dd76af2dac461ab75c030575d52bad168237474b53735eec9f9522ef080aca1100e08f320f38e12e21863fbdc3816300000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000020000000000000000000000000cf06ec4f5f4d8c4fedd2f5484448ef0e5709520b0000000000000000000000000000000000000000000000000000000000000001",
            "signature":"0x5ed416cc48673d0ed3e7b5cecc30563c4b0ff9dce4915ce96c9b87426787de5245d55a065512e7fd1bf1a18f183992d5164a73762cd43f73a88e13480a5a7e211c"
        },
        "document_token_id":"b8dd76af-2dac-461a-b75c-030575d52bad"
    }
]

It is the response of the previous call but with each of the relayed_transaction objects annotated with a signature.

This call instructs the backend to issue the transaction on the blockchain.