Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to build transaction whose input is from zero address and output is also zero address? #221

Closed
golddydev opened this issue Sep 7, 2023 · 2 comments

Comments

@golddydev
Copy link

I am now build dApp.
And I want to verify users by letting them signData using their wallets.
But the problem is that Ledger type wallet (not seed-phrase account) doesn't support signData method yet.
So I was trying to use signTx method instead.
But how can we build tx which is not related to users' address, so they see that nothing will happen after they sign the Transaction.

@golddydev
Copy link
Author

Hi, I solved this issue.
We can do this using lucid-cardano.

The cardano zero address is here

addr1vyqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqkdl5mw
const inputs = C.TransactionInputs.new();
inputs.add(
  C.TransactionInput.new(
    C.TransactionHash.from_hex(
      '706f481e44126b9de1c394e1ade248b15c435216fba3ecfb40d21c5c291be75d',
    ),
    C.BigNum.zero(),
  ),
);
const outputs = C.TransactionOutputs.new();
outputs.add(
  C.TransactionOutput.new(
    C.Address.from_bech32(
      'addr1qx2vnfzpeuvdcym8y7v5qnz2mc289ue6tfr0xynyaqnm0rhuanngtqdu53qy0c0zxxed8hdnmkl66l0uvw68q8elp4nsxyap30',
    ),
    C.Value.new(C.BigNum.from_str('1000000')),
  ),
);
const fee = C.BigNum.from_str('500000');
const witnessSet = C.TransactionWitnessSet.new();
const auxData = C.AuxiliaryData.new();
const metadata = C.GeneralTransactionMetadata.new();
const metadataMap = C.MetadataMap.new();
const metadataList = C.MetadataList.new();
metadataList.add(C.TransactionMetadatum.new_text('Hello World'));
metadataMap.insert(
  C.TransactionMetadatum.new_text('msg'),
  C.TransactionMetadatum.new_list(metadataList),
);
const metadataum = C.TransactionMetadatum.new_map(metadataMap);
metadata.insert(C.BigNum.from_str('674'), metadataum);
auxData.set_metadata(metadata);
const transaction = C.Transaction.new(
  C.TransactionBody.new(inputs, outputs, fee),
  witnessSet,
  auxData,
);

@golddydev
Copy link
Author

Here is easier way for this.

const lucid = await Lucid.new(blockfrostProvider, 'Mainnet');
const utxos = await lucid.utxosAt(zeroAddress);
lucid.selectWalletFrom({
  address: zeroAddress,
  utxos,
});
const tx = await lucid
  .newTx()
  .payToAddress(bech32Address, {
    lovelace: 2000000n,
  })
  .addSigner(bech32Address)
  .validTo(Date.now() + 1000 * 120)
  .attachMetadata(674, {
    msg: [
      'Only for verification',
    ],
  })
  .complete();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant