dashevo / js-dash-sdk

DEPRECATED Dash client-side library for wallet payment/signing and application development. (Wallet, DAPI, Primitives, BLS, ...)
https://dashevo.github.io/platform/SDK/
MIT License
36 stars 21 forks source link

Registering a name throws error: Cannot read property 'isDocumentDefined' of null #175

Closed dashameter closed 3 years ago

dashameter commented 3 years ago

Registering a name throws error:

Something went wrong:
 TypeError: Cannot read property 'isDocumentDefined' of null
    at DocumentFactory.create (node_modules/@dashevo/dpp/lib/document/DocumentFactory.js:42:23)
    at DocumentFacade.create (node_modules/@dashevo/dpp/lib/document/DocumentFacade.js:43:25)
    at Platform.<anonymous> (node_modules/dash/build/src/SDK/Client/Platform/methods/documents/create.js:62:56)
    at step (node_modules/dash/build/src/SDK/Client/Platform/methods/documents/create.js:33:23)
    at Object.next (node_modules/dash/build/src/SDK/Client/Platform/methods/documents/create.js:14:53)
    at fulfilled (node_modules/dash/build/src/SDK/Client/Platform/methods/documents/create.js:5:58)

To reproduce:

const Dash = require('dash');
const axios = require('axios')

const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms))

const clientOpts = {
  network: 'evonet',
  dapiAddresses: ['127.0.0.1:3000'],
  wallet: {
    mnemonic: null, // this indicates that we want a new wallet to be generated
                    // if you want to get a new address for an existing wallet
                    // replace 'null' with an existing wallet mnemonic
  },
};

const client = new Dash.Client(clientOpts);

const createWallet = async () => {
  client.account = await client.getWalletAccount();

  const mnemonic = client.wallet.exportWallet();
  const address = client.account.getUnusedAddress();
  console.log('Mnemonic:', mnemonic);
  console.log('Unused address:', address.address);
  return address.address
};

const receiveFaucetDrop = async (address) => {
  await axios.get(`http://127.0.0.1:5050/drip/${address}`)

  let confirmedBalance = client.account.getConfirmedBalance()
  let unconfirmedBalance = client.account.getUnconfirmedBalance()

  console.log('confirmedBalance :>> ', confirmedBalance);
  console.log('unconfirmedBalance :>> ', unconfirmedBalance);

  while (confirmedBalance < 10000) {
    await sleep(100)

    confirmedBalance = client.account.getConfirmedBalance()
    unconfirmedBalance = client.account.getUnconfirmedBalance()

    console.log('confirmedBalance :>> ', confirmedBalance);
    console.log('unconfirmedBalance :>> ', unconfirmedBalance);
  }

} 

const createIdentity = async () => {
  console.log("Registering Identity..")

  const identity = await client.platform.identities.register()

  console.log('identity :>> ', identity);

  return identity
};

const registerName = async (identity) => {
  const platform = client.platform;

  const nameRegistration = await platform.names.register(
    'myFirstDashName.dash',
    { dashUniqueIdentityId: identity.getId() },
    identity,
  );

  console.log('nameRegistration :>> ', nameRegistration);

  return nameRegistration;
};

createWallet()
  .then((address) => receiveFaucetDrop(address))
  .then(()=> createIdentity())
  .then((identity) => registerName(identity))
  .catch((e) => console.error('Something went wrong:\n', e))
  .finally(() => client.disconnect());
minhquangthan commented 3 years ago

Do we have any plans to fix this bug? I can't create a name or submit document because of this. Or just let me know if I can do something to help. I think this caused by dataContract is null: create(dataContract, ownerId, type, data = {}) { if (!dataContract.isDocumentDefined(type)) { throw new InvalidDocumentTypeError(type, dataContract); } in dpp/lib/document/DocumentFactory.js:42:23

and the dataContract is null when it's trying to create and prepare documents for the platform dataContract = _b.sent();

Alex-Werner commented 3 years ago

This actually happen during times where testnet is reset and therefore contractID hardcoded are not able to fetch contract. The way to fix it is to provide the right apps id to dashJS. Working on improving the error so it better highlight what is going wrong.

thephez commented 3 years ago

@Alex-Werner Just deleted your duplicate comment

dashameter commented 3 years ago

retested successfully on v.20 with dashmate, closing issue