Error while requesting on chain randomness using a vrf service [typescript SDK]

  • Repo to reproduce the issue REPO
  • I was going through this Code , this is for generating vrf on chain in fuel. I created a similar contract which u can find here . this is the relevant code
 #[payable]
    fn request_random_number(seed: b256) {
        //let sender = msg_sender().unwrap();
        let amount = msg_amount();
        let msg_asset = msg_asset_id();

        require(msg_asset == AssetId::base(),"invalid-asset");

        let vrf = abi(Vrf, VRF_ID);
        let fee = vrf.get_fee(AssetId::base());

        require(fee == amount,"invalid-fee");

        let _ = vrf.request {
            gas: 1_000_000,
            asset_id: AssetId::base().bits(),
            coins: fee,
        }(seed);
    }

the code compiles and the contract is deployed succesfully, but when I try to call this function using the typescript sdk I get an error

 let get_fee = await contract.functions.rng_cost().get();
  console.log("rng cost fee : ", get_fee.value.toString());

  console.log("....... testing attempt 1 (1st seed) .......")

  const seed1 = generateSeed();

  console.log("seed1 generated: ",seed1.toString());

  const txn_request = await contract.functions.request_random_number(seed1).callParams({
    forward: [get_fee.value.toString(), baseAssetId],
  }).call();
  console.log("Transaction Id(request): ", txn_request.transactionId);
  • This is the error
> vrf_rng@1.0.0 test_contract /home/divy/fuel/Vrf_SampleRNG/vrf_rng
> pnpx ts-node scripts/test_contract.ts

The Fuel Node that you are trying to connect to is using fuel-core version 0.31.0,
which is not supported by the version of the TS SDK that you are using.
Things may not work as expected.
Supported fuel-core version: 0.26.0.
Your imported wallet Address:  fuel1yyvjlxdss79nklvt9cfuzthctr9fqj4ph5gu2hpwptcp7mjzex4skvqlsf
Your imported wallet Address(b256):  0x21192f99b0878b3b7d8b2e13c12ef858ca904aa1bd11c55c2e0af01f6e42c9ab
rng cost fee :  100
....... testing attempt 1 (1st seed) .......
seed1 generated:  0xbeed3282c4e6f5905e3800644c7b90408599783307f294c046d6438bc0da4b01
/home/divy/fuel/Vrf_SampleRNG/vrf_rng/node_modules/.pnpm/@fuel-ts+abi-coder@0.88.0/node_modules/@fuel-ts/abi-coder/src/Interface.ts:80
      throw new FuelError(
            ^
_FuelError: Log type with logId '16546776185816187435' doesn't exist in the ABI.
    at Interface.decodeLog (/home/divy/fuel/Vrf_SampleRNG/vrf_rng/node_modules/.pnpm/@fuel-ts+abi-coder@0.88.0/node_modules/@fuel-ts/abi-coder/src/Interface.ts:80:13)
    at /home/divy/fuel/Vrf_SampleRNG/vrf_rng/node_modules/.pnpm/@fuel-ts+account@0.88.0/node_modules/@fuel-ts/account/src/providers/transaction-response/getDecodedLogs.ts:38:43
    at Array.reduce (<anonymous>)
    at getDecodedLogs (/home/divy/fuel/Vrf_SampleRNG/vrf_rng/node_modules/.pnpm/@fuel-ts+account@0.88.0/node_modules/@fuel-ts/account/src/providers/transaction-response/getDecodedLogs.ts:29:19)
    at TransactionResponse.waitForResult (/home/divy/fuel/Vrf_SampleRNG/vrf_rng/node_modules/.pnpm/@fuel-ts+account@0.88.0/node_modules/@fuel-ts/account/src/providers/transaction-response/transaction-response.ts:262:14)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Function.build (/home/divy/fuel/Vrf_SampleRNG/vrf_rng/node_modules/.pnpm/@fuel-ts+program@0.88.0/node_modules/@fuel-ts/program/src/functions/invocation-results.ts:185:22)
    at async /home/divy/fuel/Vrf_SampleRNG/vrf_rng/scripts/test_contract.ts:41:23 {
  VERSIONS: { FORC: '0.59.0', FUEL_CORE: '0.26.0', FUELS: '0.88.0' },
  metadata: {},
  code: 'log-type-not-found'
}
 ELIFECYCLE  Command failed with exit code 1.

  • fuelup show output
   Default host: x86_64-unknown-linux-gnu
fuelup home: /home/divy/.fuelup

Installed toolchains
--------------------
latest-x86_64-unknown-linux-gnu (default)
nightly-x86_64-unknown-linux-gnu
testnet-x86_64-unknown-linux-gnu

active toolchain
----------------
latest-x86_64-unknown-linux-gnu (default)
 forc : 0.61.2
   - forc-client
     - forc-deploy : 0.61.2
     - forc-run : 0.61.2
   - forc-crypto : 0.61.2
   - forc-debug : 0.61.2
   - forc-doc : 0.61.2
   - forc-fmt : 0.61.2
   - forc-lsp : 0.61.2
   - forc-tx : 0.61.2
   - forc-wallet : 0.8.1
 fuel-core : 0.30.0
 fuel-core-keygen : 0.30.0

fuels versions
--------------
forc : 0.64.0
forc-wallet : 0.64.0

  • you can find all the relevant information regarding executing scripts Here
2 Likes

hey @lokesh-lync, can you try updating the fuels version to 0.91.0 here and try again?

tried it! Did not work.

Can you try updating the toolchain, as our latest fuel core version is 0.31.0? It’d be best if all the versions you are using are latest

@div-lync please take a look here!

Tried , But did not work

Hey @div-lync :wave:

I can see you’re making a inter contract call.

You will need to add these contracts (via the addContracts method) to the function calls for both rng_cost and request_random_number.

You can find all the relevant documentation here.

(Moved to the TypeScript SDK forum section)

Thanks , It worked after using addContracts method

  • Output
> vrf_rng@1.0.0 test_contract /home/divy/fuel/Vrf_SampleRNG/vrf_rng
> pnpx ts-node scripts/test_contract.ts

The Fuel Node that you are trying to connect to is using fuel-core version 0.31.0,
which is not supported by the version of the TS SDK that you are using.
Things may not work as expected.
Supported fuel-core version: 0.30.0.
Your imported wallet Address:  fuel1yyvjlxdss79nklvt9cfuzthctr9fqj4ph5gu2hpwptcp7mjzex4skvqlsf
Your imported wallet Address(b256):  0x21192f99b0878b3b7d8b2e13c12ef858ca904aa1bd11c55c2e0af01f6e42c9ab
rng cost fee :  100
....... testing attempt 1 (1st seed) .......
seed1 generated:  0x770f7a2ee8a0d8e82345ff0ff14518d99ed338bf042f372525bacae23310db0b
Transaction Id(request):  0x94eaf68a8437405c9295e0b4ee379f063a47dec79f2e502e62aacdfec888891e
 const Vrf = VrfImplAbi__factory.connect(vrf_CONTRACT_ID, wallet);

  let get_fee = await contract.functions.rng_cost()
  .addContracts([Vrf])
  .get();
  console.log("rng cost fee : ", get_fee.value.toString());

  console.log("....... testing attempt 1 (1st seed) .......")

  const seed1 = generateSeed();

  console.log("seed1 generated: ",seed1.toString());

  const txn_request = await contract.functions.request_random_number(seed1)
  .callParams({
    forward: [get_fee.value.toString(), baseAssetId],
  })
  .addContracts([Vrf])
  .call();
  console.log("Transaction Id(request): ", txn_request.transactionId);
2 Likes

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.