@ethersproject/abstract-signer#VoidSigner TypeScript Examples

The following examples show how to use @ethersproject/abstract-signer#VoidSigner. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.ts    From pownft-miner with Apache License 2.0 5 votes vote down vote up
async function main() {

    const { provider, signer, numCores, chunkSize, gasLimit, dryRun } = loadConfig();
    
    const address = await signer.getAddress();
    console.log(`Miner configured with address ${address} using ${numCores} cores`);

    if (dryRun) {
        console.log("Running in dry run mode, no transactions will be submitted")
    }

    // guard, use a read-only signer while mining
    const voidSigner = new VoidSigner(address, provider);
    const instance = powNftContract(voidSigner);

    const targetAtom = await mineNextAtom({
        numThreads: numCores,
        provider,
        instance,
        signerAddress: address,
        chunkSize,
    });

    console.log('Found atom!! Trying to submit tx...');

    const gasPrices = await getGasPrices();
    if (BigNumber.from(gasPrices.rapid).gt(gasLimit)) {
        throw Error(`Gas too expensive, the max is ${formatUnits(gasLimit, 'gwei')}! Not going to mine`);
    }
    console.log(`Gas price ${formatUnits(gasPrices.rapid, 'gwei')} is below the max of ${formatUnits(gasLimit, 'gwei')}`);

    if (dryRun) {
        console.log('Dry run mode, estimating gas but will not issue tx');
        const tx = await mineAtom(instance, targetAtom, BigNumber.from(gasPrices.rapid), dryRun);
    } else {
        // use the real signer
        const liveInstance = powNftContract(signer);
        const tx = (await mineAtom(liveInstance, targetAtom, BigNumber.from(gasPrices.rapid), dryRun)) as TransactionResponse;
        console.log(`Submitted transaction ${tx.hash}`);
        const txReceipt = await tx.wait();
        console.log('Transaction mined!');
    }
    
}