rober-m / reproduce-no-traces-blockfrost

0 stars 0 forks source link

little problem #1

Open vladimirvolek opened 2 days ago

vladimirvolek commented 2 days ago

The code:

import { BlockfrostProvider, MeshWallet, Mint, PlutusScript, Transaction } from "@meshsdk/core";
import { applyCborEncoding } from "@meshsdk/core-csl";
import { BlockFrostAPI } from '@blockfrost/blockfrost-js';
import fs from 'fs';

const BLOCKFROST_API_KEY = 'preprodHxmUGBu7tBPJ38rCBXRbOMVLabLOH62m'

// Prepare Blockfrost API for blockfrost-js
const API = new BlockFrostAPI({
  projectId: BLOCKFROST_API_KEY,
  network: 'preprod'
});

// Prepare Blockfrost provider for MeshSDK
const blockchainProvider = new BlockfrostProvider(BLOCKFROST_API_KEY);
// dadaffcd0c08cdaffd707655f9b15029c6f922cfcd50fc4f2f15a49953a0b3b94011019c556dc284ce0198345368391b7e063ce17c0035e8075f87fd6b9847fa
// xprv1eqlx0yvuu88uu7t434x9mxmy797y6sm44krvelhflys0fd3r09yjqe5e23sl7yxfq48kpzfk2c3u00fr5zlw0pq8crlxcuxk6wl3mtju3hjqup9t0jypsgvg68wkdgtuej7u23408wmzzyq90ul8suvevg5efc39
// Create a new wallet
// fs.writeFileSync(`wallet.skey`, MeshWallet.brew(true) as string);

// console.log('blockchainProvider', blockchainProvider)

// Initialize the wallet with a mnemonic key
const wallet = new MeshWallet({
  networkId: 0,
  fetcher: blockchainProvider,
  submitter: blockchainProvider,
  key: {
    type: 'root',
    bech32: fs.readFileSync(`wallet.skey`).toString().trim()
  },
});

// Check if the wallet has funds
// console.log(wallet)
console.log("Wallet address: ", wallet.getChangeAddress());
console.log("Wallet Lovelace balance: ", await wallet.getLovelace());

// Prepare validator
const alwaysFalseVithTracesScript: PlutusScript = {
  code: applyCborEncoding("58980101003232323232253330023232323232533008490117746869732069732061207472616365206d6573736167650015330084911d7468697320697320616e6f74686572207472616365206d6573736167650014a06012601400460100026010004600c00260086ea800452615330034911856616c696461746f722072657475726e65642066616c736500136565734ae7155cf2ba157441"),
  version: "V3",
};

// Prepare dummy asset to mint
const asset: Mint = {
  assetName: 'TestToken',
  assetQuantity: '1',
  metadata: {},
  label: '721',
  recipient: 'addr_test1qrcsu0x34ye9dv5rdcnvzs5fyszf09zfkvr75lqwljlkj3r7cm477qh03xkw55pjta25uvumutk48msee9prpythw0sqev8r56'
};

// Prepare dummy redeemer
const redeemer = {
  data: { alternative: 0, fields: [] },
};

// Create transaction with parameters that I care
const tx = new Transaction({ initiator: wallet })
  .mintAsset(alwaysFalseVithTracesScript, asset, redeemer)
  .setNetwork('preprod')
  .setChangeAddress(wallet.getChangeAddress())

// Balance Tx
const unsignedTx = await tx.build();
// Sign Tx
const signedTx = wallet.signTx(unsignedTx);
// Inspect Tx
console.debug("txJSON: \n", JSON.stringify(tx.txBuilder.meshTxBuilderBody));
// Evaluate Tx with blockfrost-js
console.log("evaluateTx with blockfrost-js: \n", await API.utilsTxsEvaluate(signedTx));
// Submit Tx with blockfrost-js
//console.log("submit tx with blockfrost-js: ", await API.txSubmit(signedTx));

// Evaluate Tx with MeshSDK
//console.log("evaluateTx(): ", JSON.parse(await blockchainProvider.evaluateTx(signedTx)).result);
// Submit Tx with MeshSDK
//const txHash = await wallet.submitTx(signedTx);

Result:

npx tsx index.ts
blockchainProvider BlockfrostProvider {
  _axiosInstance: [Function: wrap] {
    constructor: [Function: wrap],
    request: [Function: wrap],
    _request: [Function: wrap],
    getUri: [Function: wrap],
    delete: [Function: wrap],
    get: [Function: wrap],
    head: [Function: wrap],
    options: [Function: wrap],
    post: [Function: wrap],
    postForm: [Function: wrap],
    put: [Function: wrap],
    putForm: [Function: wrap],
    patch: [Function: wrap],
    patchForm: [Function: wrap],
    defaults: {
      transitional: [Object],
      adapter: [Array],
      transformRequest: [Array],
      transformResponse: [Array],
      timeout: 0,
      xsrfCookieName: 'XSRF-TOKEN',
      xsrfHeaderName: 'X-XSRF-TOKEN',
      maxContentLength: -1,
      maxBodyLength: -1,
      env: [Object],
      validateStatus: [Function: validateStatus],
      headers: [Object],
      baseURL: 'https://cardano-preprod.blockfrost.io/api/v0'
    },
    interceptors: { request: [InterceptorManager], response: [InterceptorManager] },
    create: [Function: create]
  },
  _network: 'preprod',
  resolveScriptRef: [AsyncFunction: resolveScriptRef],
  toUTxO: [AsyncFunction: toUTxO]
}
Wallet address:  addr_test1qq7ta7dc00pp5nen7nh9z7hcf4r76ekgenwrt8we7upeegqpqhn850r08ms4d60g34peg3uamv80h5t3ef33l5en6ztqu9qjz7
Wallet Lovelace balance:  100000000
file:///Users/vladimir/fb/reproduce-no-traces-blockfrost/off-chain/node_modules/@meshsdk/transaction/dist/index.js:1732
      throw Error(
            ^

Error: Transaction information is incomplete while no fetcher instance is provided
    at MeshTxBuilder.queryAllTxInfo (file:///Users/vladimir/fb/reproduce-no-traces-blockfrost/off-chain/node_modules/@meshsdk/transaction/dist/index.js:1732:13)
    at MeshTxBuilder.complete (file:///Users/vladimir/fb/reproduce-no-traces-blockfrost/off-chain/node_modules/@meshsdk/transaction/dist/index.js:1624:16)
    at Transaction.build (file:///Users/vladimir/fb/reproduce-no-traces-blockfrost/off-chain/node_modules/@meshsdk/transaction/dist/index.js:2382:29)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at <anonymous> (/Users/vladimir/fb/reproduce-no-traces-blockfrost/off-chain/index.ts:66:20)

Node.js v20.10.0
rober-m commented 2 days ago

I can't seem to reproduce the issue 😓. I diff to check for differences and even copy-pasted your script and ran it using your Blockfrost key and skey and still got:

➜  off-chain git:(main) ✗ npx tsx issue.ts
Wallet address:  addr_test1qq7ta7dc00pp5nen7nh9z7hcf4r76ekgenwrt8we7upeegqpqhn850r08ms4d60g34peg3uamv80h5t3ef33l5en6ztqu9qjz7
Wallet Lovelace balance:  100000000
txJSON:
 {"inputs":[{"type":"PubKey","txIn":{"txHash":"ea0193498dded11996ae95e6bb5431ecb1738e6c1078aa5dbc90dd6d766e18dd","txIndex":0,"amount":[{"unit":"lovelace","quantity":"100000000"}],"address":"addr_test1qq7ta7dc00pp5nen7nh9z7hcf4r76ekgenwrt8we7upeegqpqhn850r08ms4d60g34peg3uamv80h5t3ef33l5en6ztqu9qjz7"}}],"outputs":[{"address":"addr_test1qrcsu0x34ye9dv5rdcnvzs5fyszf09zfkvr75lqwljlkj3r7cm477qh03xkw55pjta25uvumutk48msee9prpythw0sqev8r56","amount":[{"unit":"dca26fd4de08ab0d886317e65af702b163d361fdbf5f13d1ca5ba11054657374546f6b656e","quantity":"1"}]}],"extraInputs":[{"input":{"outputIndex":0,"txHash":"ea0193498dded11996ae95e6bb5431ecb1738e6c1078aa5dbc90dd6d766e18dd"},"output":{"address":"addr_test1qq7ta7dc00pp5nen7nh9z7hcf4r76ekgenwrt8we7upeegqpqhn850r08ms4d60g34peg3uamv80h5t3ef33l5en6ztqu9qjz7","amount":[{"unit":"lovelace","quantity":"100000000"}]}}],"collaterals":[{"type":"PubKey","txIn":{"txHash":"ea0193498dded11996ae95e6bb5431ecb1738e6c1078aa5dbc90dd6d766e18dd","txIndex":0,"amount":[{"unit":"lovelace","quantity":"100000000"}],"address":"addr_test1qq7ta7dc00pp5nen7nh9z7hcf4r76ekgenwrt8we7upeegqpqhn850r08ms4d60g34peg3uamv80h5t3ef33l5en6ztqu9qjz7"}}],"requiredSignatures":[],"referenceInputs":[],"mints":[{"type":"Plutus","policyId":"dca26fd4de08ab0d886317e65af702b163d361fdbf5f13d1ca5ba110","assetName":"54657374546f6b656e","amount":"1","scriptSource":{"type":"Provided","script":{"code":"589a58980101003232323232253330023232323232533008490117746869732069732061207472616365206d6573736167650015330084911d7468697320697320616e6f74686572207472616365206d6573736167650014a06012601400460100026010004600c00260086ea800452615330034911856616c696461746f722072657475726e65642066616c736500136565734ae7155cf2ba157441","version":"V3"}},"redeemer":{"data":{"type":"Mesh","content":{"alternative":0,"fields":[]}},"exUnits":{"mem":7000000,"steps":3000000000}}}],"changeAddress":"addr_test1qq7ta7dc00pp5nen7nh9z7hcf4r76ekgenwrt8we7upeegqpqhn850r08ms4d60g34peg3uamv80h5t3ef33l5en6ztqu9qjz7","metadata":[{"tag":"721","metadata":"{\"dca26fd4de08ab0d886317e65af702b163d361fdbf5f13d1ca5ba110\":{\"TestToken\":{}}}"}],"validityRange":{},"certificates":[],"withdrawals":[],"signingKey":[],"selectionConfig":{"threshold":"5000000","strategy":"experimental","includeTxFees":true},"network":"preprod"}
evaluateTx with blockfrost-js:
 {
  type: 'jsonwsp/response',
  version: '1.0',
  servicename: 'ogmios',
  methodname: 'EvaluateTx',
  result: { EvaluationFailure: { ScriptFailures: {} } },
  reflection: { id: 'db7fae75-2af2-4b3f-ab66-f4d49e9b4966' }
}

All I can think of is maybe the node version? 🤷 You're using v20.10.0 and I'm using v22.9.0

slowbackspace commented 1 day ago

I can confirm I can run @vladimirvolek code just fine and reproduce the issue with both nodejs versions!

Wallet address:  addr_test1qpqjxm4xm77fudprzna4xdk5d98dd9peatye8v9ws6fe2c8hacantdtgd4pj5y4kv2v4nrtl5332msgjl8rgsvqdhm4qc80tcz
Wallet Lovelace balance:  20000000
txJSON: 
 {"inputs":[{"type":"PubKey","txIn":{"txHash":"1f7363a2765d69f6291a17e38dffef447bacad06c8f5441fd746c80a6a51562b","txIndex":0,"amount":[{"unit":"lovelace","quantity":"20000000"}],"address":"addr_test1qpqjxm4xm77fudprzna4xdk5d98dd9peatye8v9ws6fe2c8hacantdtgd4pj5y4kv2v4nrtl5332msgjl8rgsvqdhm4qc80tcz"}}],"outputs":[{"address":"addr_test1qrcsu0x34ye9dv5rdcnvzs5fyszf09zfkvr75lqwljlkj3r7cm477qh03xkw55pjta25uvumutk48msee9prpythw0sqev8r56","amount":[{"unit":"dca26fd4de08ab0d886317e65af702b163d361fdbf5f13d1ca5ba11054657374546f6b656e","quantity":"1"}]}],"extraInputs":[{"input":{"outputIndex":0,"txHash":"1f7363a2765d69f6291a17e38dffef447bacad06c8f5441fd746c80a6a51562b"},"output":{"address":"addr_test1qpqjxm4xm77fudprzna4xdk5d98dd9peatye8v9ws6fe2c8hacantdtgd4pj5y4kv2v4nrtl5332msgjl8rgsvqdhm4qc80tcz","amount":[{"unit":"lovelace","quantity":"20000000"}]}}],"collaterals":[{"type":"PubKey","txIn":{"txHash":"1f7363a2765d69f6291a17e38dffef447bacad06c8f5441fd746c80a6a51562b","txIndex":0,"amount":[{"unit":"lovelace","quantity":"20000000"}],"address":"addr_test1qpqjxm4xm77fudprzna4xdk5d98dd9peatye8v9ws6fe2c8hacantdtgd4pj5y4kv2v4nrtl5332msgjl8rgsvqdhm4qc80tcz"}}],"requiredSignatures":[],"referenceInputs":[],"mints":[{"type":"Plutus","policyId":"dca26fd4de08ab0d886317e65af702b163d361fdbf5f13d1ca5ba110","assetName":"54657374546f6b656e","amount":"1","scriptSource":{"type":"Provided","script":{"code":"589a58980101003232323232253330023232323232533008490117746869732069732061207472616365206d6573736167650015330084911d7468697320697320616e6f74686572207472616365206d6573736167650014a06012601400460100026010004600c00260086ea800452615330034911856616c696461746f722072657475726e65642066616c736500136565734ae7155cf2ba157441","version":"V3"}},"redeemer":{"data":{"type":"Mesh","content":{"alternative":0,"fields":[]}},"exUnits":{"mem":7000000,"steps":3000000000}}}],"changeAddress":"addr_test1qpqjxm4xm77fudprzna4xdk5d98dd9peatye8v9ws6fe2c8hacantdtgd4pj5y4kv2v4nrtl5332msgjl8rgsvqdhm4qc80tcz","metadata":[{"tag":"721","metadata":"{\"dca26fd4de08ab0d886317e65af702b163d361fdbf5f13d1ca5ba110\":{\"TestToken\":{}}}"}],"validityRange":{},"certificates":[],"withdrawals":[],"signingKey":[],"selectionConfig":{"threshold":"5000000","strategy":"experimental","includeTxFees":true},"network":"preprod"}
evaluateTx with blockfrost-js: 
 {
  type: 'jsonwsp/response',
  version: '1.0',
  servicename: 'ogmios',
  methodname: 'EvaluateTx',
  result: { EvaluationFailure: { ScriptFailures: {} } },
  reflection: { id: 'cbdffd2c-3e04-46f7-9712-d83289c816df' }
}