I tried the price fetch offchainworker test you made. I try to call api using the polkadotjs library, but an error occurs because the type is not defined. I have attached the code I tested. Likewise, the frontend you created will get the same error. Please define the type so that my javascript can work.
-----------------------------------my javascript code (block.js)-------------------------------------
var { ApiPromise, WsProvider, Keyring } = require('@polkadot/api');
var { cryptoWaitReady } = require('@polkadot/util-crypto');
var { stringToU8a, u8aToHex } = require('@polkadot/util');
//var { createType } = require('@polkadot/types');
const BOB = '1KvKReVmUiTc2LW2a4qyHsaJJ9eE9LRsywZkMk5hyBeyHgw';
const JAY = '15j4dg5GzsL1bw2U2AWgeyAk6QTxq43V7ZPbXdAmbVLjvDCK';
async function main () {
await cryptoWaitReady();
const provider = new WsProvider('ws://localhost::9944');
//const provider = new WsProvider('wss://rpc.polkadot.io');
const api = await ApiPromise.create({ provider});
console.log(api.genesisHash.toHex());
return
const [chain, nodeName, nodeVersion] = await Promise.all([
api.rpc.system.chain(),
api.rpc.system.name(),
api.rpc.system.version()
]);
console.log(You are connected to chain ${chain} using ${nodeName} v${nodeVersion}
);
var keyring = new Keyring({ type : 'sr25519'});
var alice = keyring.addFromUri('//Alice');
var transfer = api.tx.balances.transfer(JAY, 100);
//console.log("transfer:", transfer);
const hash = await transfer.signAndSend(BOB);
console.log('Transfer sent with hash', hash.toHex());
var PHRASE = 'entire material egg meadow latin bargain dutch coral blood melt acoustic thought';
var newPair = keyring.addFromUri(PHRASE);
var alice = keyring.addFromUri('//Alice', { name: 'Alice default' });
//console.log(${alice.meta.name}: has address ${alice.address} with publicKey [${alice.publicKey}]
);
const message = stringToU8a('this is our message');
const signature = alice.sign(message);
const isValid = alice.verify(message, signature);
//console.log(The signature ${u8aToHex(signature)}, is ${isValid ? '' : 'in'}valid
);
var chain1 = await api.rpc.system.chain();
var lastHeader = await api.rpc.chain.getHeader();
console.log(${chain1}: last block #${lastHeader.number} has hash ${lastHeader.hash}
);
console.log(api.consts.babe.epochDuration.toNumber());
let { data: { free: previousFree }, nonce: previousNonce } = await api.query.system.account(BOB);
console.log(${BOB} has a balance of ${previousFree}, nonce ${previousNonce}
);
}
main().catch(console.error).finally(() => process.exit());
-----------------error---------------------------------
[root@localhost api_test]# node block.js
Unable to resolve type StrVecBytes, it will fail on construction
Unknown types found, no types for StrVecBytes
Unable to decode Vec on index 1 createType(ExtrinsicV4):: createType(Call):: Struct: failed on 'args':: Cannot construct unknown type StrVecBytes
2020-09-26 06:21:12 RPC-CORE: getBlock(hash?: BlockHash): SignedBlock:: createType(SignedBlock):: Struct: failed on 'block':: Struct: failed on 'extrinsics':: createType(ExtrinsicV4):: createType(Call):: Struct: failed on 'args':: Cannot construct unknown type StrVecBytes
2020-09-26 06:21:12 API/INIT: Error: FATAL: Unable to initialize the API: createType(SignedBlock):: Struct: failed on 'block':: Struct: failed on 'extrinsics':: createType(ExtrinsicV4):: createType(Call):: Struct: failed on 'args':: Cannot construct unknown type StrVecBytes
at EventEmitter.value (/home/api_test/node_modules/@polkadot/api/base/Init.js:85:25)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:4282) UnhandledPromiseRejectionWarning: Error: FATAL: Unable to initialize the API: createType(SignedBlock):: Struct: failed on 'block':: Struct: failed on 'extrinsics':: createType(ExtrinsicV4):: createType(Call):: Struct: failed on 'args':: Cannot construct unknown type StrVecBytes
at EventEmitter.value (/home/api_test/node_modules/@polkadot/api/base/Init.js:85:25)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:4282) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:4282) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.