<p>The problem was that I was trying to use the <code>cardano-cli</code> command for address to a stake-address. The command for payment credential (<code>PubKeyHash</code>) is correct in the question:</p>
<p><code>cardano-cli address key-hash --payment-verification-key-file payment.vkey</code></p>
<p>The correct command for staking credential should be like this:</p>
<p><code>cardano-cli stake-address key-hash --stake-verification-key-file stake.vkey</code></p>
<p>Outputs of those 2 commands can be used to build correct <code>Address</code> in datum.</p>
<p>Also, the JSON I provided in the question is incorrect, the staking credential part should be deeper than the payment credential part, you can get the correct JSON by printing the datum in emulator using a command like in an answer to <a href="https://cardano.stackexchange.com/questions/4276/convert-redeemer-datum-or-script-parameter-to-json">this</a> question.</p>

CC BY-SA 4.0
2022-01-08T13:28:33.497Z
So then, are you embedding an address-hash of some sort in the datum? As far as I know, you can't recreate the full address using the hashes of the constituent keys. I'm just curious - is the purpose of this to embed the address hash or some sort of address-verification method into the datum?
zhekson
CC BY-SA 4.0
2022-01-08T18:39:48.013Z
I think that payment credential and staking credential are just hashes, so you can verify that an output goes to an address from datum without the need to reconstruct the full address.
ijkl26
CC BY-SA 4.0
2022-12-15T00:57:56.520Z
You write "the JSON I provided is incorrect".  Would you please paste the correct JSON? I am lost from the links and your explanation is too vague
ZachSweet
CC BY-SA 4.0
2022-01-08T08:46:20.033Z
2022-01-08T18:42:51.473Z
2022-01-08T18:42:51.473Z
ijkl26
<p>I have a validator that uses <code>Address</code> in datum. I also have an address generated (<code>payment.vkey</code>, <code>payment.skey</code>, <code>payment.addr</code>, <code>stake.vkey</code>, <code>stake.skey</code>, <code>stake.addr</code>). I'm able to get <code>PubKeyHash</code> using command line like this:</p>
<p><code>cardano-cli address key-hash --payment-verification-key-file payment.vkey</code></p>
<p>That gives an <code>addressPaymentCredential</code> that I'm able to embed to datum when building the transaction in cli. It has the same information as <code>(addressPaymentCredential, _)</code>. How would I go about getting a full address with <code>addressStakingCredential</code> in it, that is, <code>(addressPaymentCredential, addressStakingCredential)</code>?</p>
<p>I think that the <code>JSON</code> structure of <code>Address</code> in datum should be like this:</p>
<pre><code>{
  &quot;constructor&quot;: 0,
  &quot;fields&quot;: [
    {
      &quot;constructor&quot;: 0,
      &quot;fields&quot;: [
        {
          &quot;bytes&quot;: PubKeyHash
        }
      ]
    },
    {
      &quot;constructor&quot;: 1,
      &quot;fields&quot;: [
        {
          &quot;bytes&quot;: StakingCredentialHash
        }
      ]
    }
  ]
}
</code></pre>
<p>My problem is I don't know how to get <code>StakingCredentialHash</code>.</p>
<p><strong>TLDR</strong>: How do I embedd an <code>Address</code> instead of just <code>PubKeyHash</code> into the datum in cardano cli? I have the address credentials in <code>payment.*</code> and <code>stake.*</code> files.</p>

CC BY-SA 4.0
2022-01-07T17:52:22.577Z
why not just use the address instead of PubKeyHash in your example?
noone392
CC BY-SA 4.0
2022-01-07T18:27:16.900Z
@noone392 You mean in the JSON? The whole JSON is an Address which is composed of two parts, one of them being PubKeyHash. My validator used PubKeyHash, but I'm trying to replace it with Address. I did that and now I need to change the datum JSON appropriately. Or do you mean something else?
ijkl26
CC BY-SA 4.0
2022-01-07T20:29:38.467Z
I am not following you. The JSON file is not the address it is the whole formatting required for a datum entry. you said you said you wanted the address instead of the public key hash. So just delete "bytes": PubKeyHash  and replace with "bytes": address? or if you want to add the address then add another "fields" key
noone392
CC BY-SA 4.0
2022-01-07T20:44:07.890Z
Yes, I want to transform my address into the datum entry. The JSON I provided is slightly modified output of `ToData a`, where `a = Address(addressCredential, addressStakingCredential)`. In the JSON provided, I can replace `PubKeyHash` (which is just a placeholder there) with the output of `cardano-cli address key-hash --payment-verification-key-file payment.vkey`. My problem is that I can't figure out, what I need to replace the `StakingCredentialHash` placeholder with. I have the `stake.vkey` file, but I need some command to transform it in a similar manner to how I did with `payment.vkey`.
ijkl26
CC BY-SA 4.0
2022-01-07T23:27:53.237Z
i really can't follow what your asking. to transform stake.vkey in the same maneer just run 
"cardano-cli address key-hash --payment-verification-key-file stake.vkey"
noone392
CC BY-SA 4.0
2022-01-08T08:43:57.700Z
I see the problem now, the command does not work on `stake.vkey`, but it needs to get `stake-address` instead of just `address`. I'll add an answer.
ijkl26
<plutus><cardano-cli><address><datum>
Embedding address into the datum using the CLI
# Embedding address into the datum using the CLI

(Asked by: username_0 on 2022-01-07)

I have a validator that uses Address in datum. I also have an address generated (payment.vkey, payment.skey, payment.addr, stake.vkey, stake.skey, stake.addr). I'm able to get PubKeyHash using command line like this:
cardano-cli address key-hash --payment-verification-key-file payment.vkey
That gives an addressPaymentCredential that I'm able to embed to datum when building the transaction in cli. It has the same information as (addressPaymentCredential, _). How would I go about getting a full address with addressStakingCredential in it, that is, (addressPaymentCredential, addressStakingCredential)?
I think that the JSON structure of Address in datum should be like this:
{
  "constructor": 0,
  "fields": [
    {
      "constructor": 0,
      "fields": [
        {
          "bytes": PubKeyHash
        }
      ]
    },
    {
      "constructor": 1,
      "fields": [
        {
          "bytes": StakingCredentialHash
        }
      ]
    }
  ]
}

My problem is I don't know how to get StakingCredentialHash.
TLDR: How do I embedd an Address instead of just PubKeyHash into the datum in cardano cli? I have the address credentials in payment.* and stake.* files.

**Tags:** plutus, cardano-cli, address, datum
> **Comments:**
> **username_1**: why not just use the address instead of PubKeyHash in your example?  
> **username_0**: @noone392 You mean in the JSON? The whole JSON is an Address which is composed of two parts, one of them being PubKeyHash. My validator used PubKeyHash, but I'm trying to replace it with Address. I did that and now I need to change the datum JSON appropriately. Or do you mean something else?  
> **username_1**: I am not following you. The JSON file is not the address it is the whole formatting required for a datum entry. you said you said you wanted the address instead of the public key hash. So just delete "bytes": PubKeyHash  and replace with "bytes": address? or if you want to add the address then add another "fields" key  
> **username_0**: Yes, I want to transform my address into the datum entry. The JSON I provided is slightly modified output of `ToData a`, where `a = Address(addressCredential, addressStakingCredential)`. In the JSON provided, I can replace `PubKeyHash` (which is just a placeholder there) with the output of `cardano-cli address key-hash --payment-verification-key-file payment.vkey`. My problem is that I can't figure out, what I need to replace the `StakingCredentialHash` placeholder with. I have the `stake.vkey` file, but I need some command to transform it in a similar manner to how I did with `payment.vkey`.  
> **username_1**: i really can't follow what your asking. to transform stake.vkey in the same maneer just run  "cardano-cli address key-hash --payment-verification-key-file stake.vkey"  
> **username_0**: I see the problem now, the command does not work on `stake.vkey`, but it needs to get `stake-address` instead of just `address`. I'll add an answer.  

---

## 1 answers

### Answer by username_0 on 2022-01-08. Score: 0

The problem was that I was trying to use the `cardano-cli` command for address to a stake-address. The command for payment credential (`PubKeyHash`) is correct in the question:

`cardano-cli address key-hash --payment-verification-key-file payment.vkey`

The correct command for staking credential should be like this:

`cardano-cli stake-address key-hash --stake-verification-key-file stake.vkey`

Outputs of those 2 commands can be used to build correct `Address` in datum.

Also, the JSON I provided in the question is incorrect, the staking credential part should be deeper than the payment credential part, you can get the correct JSON by printing the datum in emulator using a command like in an answer to [this](https://cardano.stackexchange.com/questions/4276/convert-redeemer-datum-or-script-parameter-to-json) question.

> **Comments:**
> **username_2**: So then, are you embedding an address-hash of some sort in the datum? As far as I know, you can't recreate the full address using the hashes of the constituent keys. I'm just curious - is the purpose of this to embed the address hash or some sort of address-verification method into the datum?  
> **username_0**: I think that payment credential and staking credential are just hashes, so you can verify that an output goes to an address from datum without the need to reconstruct the full address.  
> **username_3**: You write "the JSON I provided is incorrect".  Would you please paste the correct JSON? I am lost from the links and your explanation is too vague  

---

