Everything you need to know about the process to verify nonces sent by miners
Here is the full process to verify nonces sent by miners
1. Import randomx-etica-node.js
Full details of how to install randomx-etica-nodejs here:
import randomx from "randomx-etica-nodejs";
2. Get nonce and from result from miner submit request:
var nonce =interaction.params.nonce;var hashresult =interaction.params.result;
3. Load miner's Blob
The miner should have a unique blob specific for this miner. For nonce verification you need to load this minerBlob. Reserved Space
Then convert minerBlob to 0x format like this:
constminerBlob=randomxHelper.convertToRawWithout0x(this.randomxBlobWithReservedHash);(randomxHelper functions details below at bottom of the page)
4. Finally, convert inputs data in right format
const nonceBuffer = Buffer.from(nonce, 'hex');
const hashresultBuffer = Buffer.from(hashresult, 'hex');
const targetBigNumber = new BigNumber(this.target);
const targetBuffer = Buffer.from(targetBigNumber.toString(16).padStart(64, '0'), 'hex');
const seedHash = randomxHelper.convertToRawWithout0x(this.randomxSeedhash);
(randomxHelper functions details below at bottom of the page)
Check Read Etica Smart Contract section for how to retrieve the variables data from Etica Smart Contract (your system should have these variables available as vars for checks)
4. Verify Nonce
5. Make sure to save miner's extraNonce
You need to save extraNonce alongside the share data in your database system. Indeed you will need it to call the mintrandomX() Etica Smart Contract function.
Note it is the extraNonce you need, not the extraNonceHash. Check this section for details about that: Reserved Space
Here is randomxHelper.js for details about what the mentioned randomxHelper functions like convertWithout0x() do