energywebfoundation / iam-client-lib

TypeScript library to be used within decentralised applications for authentication and authorisation using DIDs (Decentralised Identifiers) and VCs (Verifiable Credentials)
GNU General Public License v3.0
19 stars 9 forks source link

createRole with private key fails with Error: cannot estimate gas #620

Closed bcowell-riis closed 2 years ago

bcowell-riis commented 2 years ago

Trying to create a script to setup an org, app and some roles with a private key. I can successfully call createOrganization and createApplication, but trying to call createRole fails with the following error

<ref *1> Error: cannot estimate gas; transaction may fail or may require manual gas limit [ See: https://links.ethers.org/v5-errors-UNPREDICTABLE_GAS_LIMIT ] (error={"reason":"processing response error","code":"SERVER_ERROR","body":"{\"jsonrpc\":\"2.0\",\"error\":{\"code\":-32016,\"message\":\"The execution failed due to an exception.\",\"data\":\"Reverted\"},\"id\":57}\n","error":{"code":-32016,"data":"Reverted"},"requestBody":"{\"method\":\"eth_estimateGas\",\"params\":[{\"type\":\"0x2\",\"maxFeePerGas\":\"0x59682f0e\",\"maxPriorityFeePerGas\":\"0x59682f00\",\"from\":\"0x9cd3d45acd43b4e504c41ce2023b6408b5fa1961\",\"to\":\"0xd7cef70ba7efc2035256d828d5287e2d285cd1ac\",\"data\":\"0x5ef2c7f079143eab4e734258dbb6dac6deb31f509fe7c585b96894abb528734adfbe7685f23ec0bb4210edd5cba85afd05127efcd2fc6a781bfed49188da1081670b22d80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000cf72f16ab886776232bea2fcf3689761a0b74efe0000000000000000000000000000000000000000000000000000000000000000\"}],\"id\":57,\"jsonrpc\":\"2.0\"}","requestMethod":"POST","url":"https://volta-rpc.energyweb.org/"}, tx={"to":{},"from":"0x9Cd3d45ACd43b4e504c41Ce2023b6408b5Fa1961","data":"0x5ef2c7f079143eab4e734258dbb6dac6deb31f509fe7c585b96894abb528734adfbe7685f23ec0bb4210edd5cba85afd05127efcd2fc6a781bfed49188da1081670b22d80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000cf72f16ab886776232bea2fcf3689761a0b74efe0000000000000000000000000000000000000000000000000000000000000000","type":2,"maxFeePerGas":{"type":"BigNumber","hex":"0x59682f0e"},"maxPriorityFeePerGas":{"type":"BigNumber","hex":"0x59682f00"},"nonce":{},"gasLimit":{},"chainId":{}}, code=UNPREDICTABLE_GAS_LIMIT, version=abstract-signer/5.6.2)
    at Logger.makeError (/Users/bcowell/Code/LaunchPoC/scripts/node_modules/iam-client-lib/node_modules/@ethersproject/wallet/node_modules/@ethersproject/logger/lib/index.js:233:21)
    at Logger.throwError (/Users/bcowell/Code/LaunchPoC/scripts/node_modules/iam-client-lib/node_modules/@ethersproject/wallet/node_modules/@ethersproject/logger/lib/index.js:242:20)
    at /Users/bcowell/Code/LaunchPoC/scripts/node_modules/iam-client-lib/node_modules/@ethersproject/wallet/node_modules/@ethersproject/abstract-signer/lib/index.js:365:47
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async Promise.all (index 7) {
  reason: 'cannot estimate gas; transaction may fail or may require manual gas limit',
  code: 'UNPREDICTABLE_GAS_LIMIT',
  error: Error: processing response error (body="{\"jsonrpc\":\"2.0\",\"error\":{\"code\":-32016,\"message\":\"The execution failed due to an exception.\",\"data\":\"Reverted\"},\"id\":57}\n", error={"code":-32016,"data":"Reverted"}, requestBody="{\"method\":\"eth_estimateGas\",\"params\":[{\"type\":\"0x2\",\"maxFeePerGas\":\"0x59682f0e\",\"maxPriorityFeePerGas\":\"0x59682f00\",\"from\":\"0x9cd3d45acd43b4e504c41ce2023b6408b5fa1961\",\"to\":\"0xd7cef70ba7efc2035256d828d5287e2d285cd1ac\",\"data\":\"0x5ef2c7f079143eab4e734258dbb6dac6deb31f509fe7c585b96894abb528734adfbe7685f23ec0bb4210edd5cba85afd05127efcd2fc6a781bfed49188da1081670b22d80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000cf72f16ab886776232bea2fcf3689761a0b74efe0000000000000000000000000000000000000000000000000000000000000000\"}],\"id\":57,\"jsonrpc\":\"2.0\"}", requestMethod="POST", url="https://volta-rpc.energyweb.org/", code=SERVER_ERROR, version=web/5.6.1)
      at Logger.makeError (/Users/bcowell/Code/LaunchPoC/scripts/node_modules/@ethersproject/logger/lib/index.js:233:21)
      at Logger.throwError (/Users/bcowell/Code/LaunchPoC/scripts/node_modules/@ethersproject/logger/lib/index.js:242:20)
      at /Users/bcowell/Code/LaunchPoC/scripts/node_modules/@ethersproject/web/lib/index.js:305:32
      at step (/Users/bcowell/Code/LaunchPoC/scripts/node_modules/@ethersproject/web/lib/index.js:33:23)
      at Object.next (/Users/bcowell/Code/LaunchPoC/scripts/node_modules/@ethersproject/web/lib/index.js:14:53)
      at fulfilled (/Users/bcowell/Code/LaunchPoC/scripts/node_modules/@ethersproject/web/lib/index.js:5:58)
      at processTicksAndRejections (internal/process/task_queues.js:95:5) {
    reason: 'processing response error',
    code: 'SERVER_ERROR',
    body: '{"jsonrpc":"2.0","error":{"code":-32016,"message":"The execution failed due to an exception.","data":"Reverted"},"id":57}\n',
    error: Error: The execution failed due to an exception.
        at getResult (/Users/bcowell/Code/LaunchPoC/scripts/node_modules/@ethersproject/providers/lib/json-rpc-provider.js:132:21)
        at processJsonFunc (/Users/bcowell/Code/LaunchPoC/scripts/node_modules/@ethersproject/web/lib/index.js:348:22)
        at /Users/bcowell/Code/LaunchPoC/scripts/node_modules/@ethersproject/web/lib/index.js:280:46
        at step (/Users/bcowell/Code/LaunchPoC/scripts/node_modules/@ethersproject/web/lib/index.js:33:23)
        at Object.next (/Users/bcowell/Code/LaunchPoC/scripts/node_modules/@ethersproject/web/lib/index.js:14:53)
        at fulfilled (/Users/bcowell/Code/LaunchPoC/scripts/node_modules/@ethersproject/web/lib/index.js:5:58)
        at processTicksAndRejections (internal/process/task_queues.js:95:5) {
      code: -32016,
      data: 'Reverted'
    },
    requestBody: '{"method":"eth_estimateGas","params":[{"type":"0x2","maxFeePerGas":"0x59682f0e","maxPriorityFeePerGas":"0x59682f00","from":"0x9cd3d45acd43b4e504c41ce2023b6408b5fa1961","to":"0xd7cef70ba7efc2035256d828d5287e2d285cd1ac","data":"0x5ef2c7f079143eab4e734258dbb6dac6deb31f509fe7c585b96894abb528734adfbe7685f23ec0bb4210edd5cba85afd05127efcd2fc6a781bfed49188da1081670b22d80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000cf72f16ab886776232bea2fcf3689761a0b74efe0000000000000000000000000000000000000000000000000000000000000000"}],"id":57,"jsonrpc":"2.0"}',
    requestMethod: 'POST',
    url: 'https://volta-rpc.energyweb.org/'
  },
  tx: {
    to: Promise { '0xd7CeF70Ba7efc2035256d828d5287e2D285CD1ac' },
    from: '0x9Cd3d45ACd43b4e504c41Ce2023b6408b5Fa1961',
    data: '0x5ef2c7f079143eab4e734258dbb6dac6deb31f509fe7c585b96894abb528734adfbe7685f23ec0bb4210edd5cba85afd05127efcd2fc6a781bfed49188da1081670b22d80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000cf72f16ab886776232bea2fcf3689761a0b74efe0000000000000000000000000000000000000000000000000000000000000000',
    type: 2,
    maxFeePerGas: BigNumber { _hex: '0x59682f0e', _isBigNumber: true },
    maxPriorityFeePerGas: BigNumber { _hex: '0x59682f00', _isBigNumber: true },
    nonce: Promise { 115 },
    gasLimit: Promise { <rejected> [Circular *1] },
    chainId: Promise { 73799 }
  }
}

Example code

const {
    signerService,
    connectToCacheServer,
  } = await initWithPrivateKeySigner(WALLET_PRIVATE_KEY, RPC_URL);
  const { did: orgOwnerDid } = signerService;

  const { domainsService } = await connectToCacheServer();

  // this works
  await domainsService.createOrganization({
    orgName: ORG_NAME,
    namespace: ROOT_NAMESPACE,
    data: {
      orgName: ORG_NAME,
    },
    returnSteps: false,
  });

  // this works too
  await domainsService.createApplication({
    appName: APP_NAME,
    namespace: APPS_NAMESPACE,
    data: {
      appName: "my app",
    },
    returnSteps: false,
  });

  // fails
    await domainsService.createRole({
    roleName: orgAdminRoleName,
    namespace: ADMIN_ROLE_NAMESPACE,
    data: {
      roleName: orgAdminRoleName,
      roleType: orgRoleType,
      version: 1,
      issuer: { issuerType: "DID", did: [orgOwnerDid] },
      revoker: { revokerType: "DID", did: [orgOwnerDid] },
    },
    returnSteps: false,
  });
bcowell-riis commented 2 years ago

Ended up being an issue with the wrong namespace!