Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot export local transaction to tenderly using cli #108

Open
peculiarity opened this issue Oct 28, 2022 · 7 comments
Open

Cannot export local transaction to tenderly using cli #108

peculiarity opened this issue Oct 28, 2022 · 7 comments

Comments

@peculiarity
Copy link

peculiarity commented Oct 28, 2022

Tenderly Current CLI version: v1.4.7
Hardhat Version: 2.12.2
Compiler version: 0.8.15

Trying to export a local transaction. It used to work bu not anymore.

The export fails with the following error message: Couldn't read Hardhat config file:
When I debug it there is this error:

[eval]:20
                var jsonConfig = JSON.stringify(config, (key, value) => {
                                      ^

TypeError: Do not know how to serialize a BigInt
    at JSON.stringify (<anonymous>)
    at [eval]:20:25
    at Script.runInThisContext (node:vm:129:12)
    at Object.runInThisContext (node:vm:305:38)
    at node:internal/process/execution:75:19
    at [eval]-wrapper:6:22
    at evalScript (node:internal/process/execution:74:60)
    at node:internal/main/eval_string:27:3

Let me know if you need anything else

Edit: With 2.8.0 hardhat it works just fine not sure where the problem is

@joyious
Copy link

joyious commented Nov 2, 2022

I have the same issue here, it seems that hardhat use bigint in the config which can not be serialized

https://github.com/NomicFoundation/hardhat/blob/hardhat%402.11.0/packages/hardhat-core/src/types/config.ts#L145

I tried downgrading the hardhat but it failed with another error, as I'm using the 0.8.x compiler

api error exporting transaction: invalid_compiler_version
Main contract compiler version not provided

@jaybuidl
Copy link

jaybuidl commented Nov 3, 2022

+1

Same issue, but using yarn workspaces in a monorepo.

Tenderly Current CLI version: v1.4.7
Hardhat Version: 2.11.2
Compiler version: 0.8.9

$ tenderly contracts push --networks 5 --project-slug my-project --output json --debug | jq .
{
    "file": "/go/pkg/mod/github.com/sirupsen/logrus@v1.4.2/logger.go:192",
    "func": "github.com/sirupsen/logrus.(*Logger).Log",
    "level": "debug",
    "msg": "unable to upload contracts: unable to fetch config: cannot evaluate hardhat.config.ts, tried path: [REDACTED]/hardhat.config.ts, error: exit status 1, output: 
...
[eval]:20
                var jsonConfig = JSON.stringify(config, (key, value) => {
                                      ^

TypeError: Do not know how to serialize a BigInt
    at JSON.stringify (<anonymous>)
    at [eval]:20:25
    at Script.runInThisContext (node:vm:129:12)
    at Object.runInThisContext (node:vm:305:38)
    at node:internal/process/execution:81:19
    at [eval]-wrapper:6:22
    at evalScript (node:internal/process/execution:80:60)
    at node:internal/main/eval_string:27:3
}

@Mrsblink
Copy link

Mrsblink commented Nov 9, 2022

same error

@fergarrui
Copy link

Same issue here

@Fr3d-
Copy link

Fr3d- commented Nov 11, 2022

Quick fix for those interested.
Add BigInt.prototype.toJSON = function() { return this.toString() } to ./node_modules/hardhat/internal/context.js

@d0ra-1h3-3xpl0ra
Copy link

I had the same issue as well:

[eval]:20
                var jsonConfig = JSON.stringify(config, (key, value) => {
                                      ^

TypeError: Do not know how to serialize a BigInt
    at JSON.stringify (<anonymous>)
    at [eval]:20:25
    at Script.runInThisContext (node:vm:129:12)
    at Object.runInThisContext (node:vm:305:38)
    at node:internal/process/execution:75:19
    at [eval]-wrapper:6:22
    at evalScript (node:internal/process/execution:74:60)
    at node:internal/main/eval_string:27:3

aaand 👍 ✅ , fixed the issue after adding it:

 BigInt.prototype.toJSON = function() { return this.toString() } to ./node_modules/hardhat/internal/context.js

your context.js could look like this
./node_modules/hardhat/internal/context.js

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.HardhatContext = void 0;
const extenders_1 = require("./core/config/extenders");
const errors_1 = require("./core/errors");
const errors_list_1 = require("./core/errors-list");
const dsl_1 = require("./core/tasks/dsl");
const platform_1 = require("./util/platform");
class HardhatContext {
    constructor() {
        this.tasksDSL = new dsl_1.TasksDSL();
        this.extendersManager = new extenders_1.ExtenderManager();
        this.configExtenders = [];
        // NOTE: This is experimental and will be removed. Please contact our team if
        // you are planning to use it.
        this.experimentalHardhatNetworkMessageTraceHooks = [];
    }
    static isCreated() {
        const globalWithHardhatContext = global;
        return globalWithHardhatContext.__hardhatContext !== undefined;
    }
    static createHardhatContext() {
        if (this.isCreated()) {
            throw new errors_1.HardhatError(errors_list_1.ERRORS.GENERAL.CONTEXT_ALREADY_CREATED);
        }
        const globalWithHardhatContext = global;
        const ctx = new HardhatContext();
        globalWithHardhatContext.__hardhatContext = ctx;
        return ctx;
    }
    static getHardhatContext() {
        const globalWithHardhatContext = global;
        const ctx = globalWithHardhatContext.__hardhatContext;
        // where the magic happens 
        BigInt.prototype.toJSON = function() { return this.toString() }
        if (ctx === undefined) {
            throw new errors_1.HardhatError(errors_list_1.ERRORS.GENERAL.CONTEXT_NOT_CREATED);
        }
        return ctx;
    }
    static deleteHardhatContext() {
        const globalAsAny = global;
        globalAsAny.__hardhatContext = undefined;
    }
    setHardhatRuntimeEnvironment(env) {
        if (this.environment !== undefined) {
            throw new errors_1.HardhatError(errors_list_1.ERRORS.GENERAL.CONTEXT_HRE_ALREADY_DEFINED);
        }
        this.environment = env;
    }
    getHardhatRuntimeEnvironment() {
        if (this.environment === undefined) {
            throw new errors_1.HardhatError(errors_list_1.ERRORS.GENERAL.CONTEXT_HRE_NOT_DEFINED);
        }
        return this.environment;
    }
    setConfigLoadingAsStarted() {
        this._filesLoadedBeforeConfig = (0, platform_1.getRequireCachedFiles)();
    }
    setConfigLoadingAsFinished() {
        this._filesLoadedAfterConfig = (0, platform_1.getRequireCachedFiles)();
    }
    getFilesLoadedDuringConfig() {
        // No config was loaded
        if (this._filesLoadedBeforeConfig === undefined) {
            return [];
        }
        (0, errors_1.assertHardhatInvariant)(this._filesLoadedAfterConfig !== undefined, "Config loading was set as started and not finished");
        return arraysDifference(this._filesLoadedAfterConfig, this._filesLoadedBeforeConfig);
    }
}
exports.HardhatContext = HardhatContext;
function arraysDifference(a, b) {
    return a.filter((e) => !b.includes(e));
}
//# sourceMappingURL=context.js.map

then just run
tenderly export [your tx hash] --force --debug

thx @Fr3d-

@peculiarity
Copy link
Author

@Fr3d- I have a better idea - Add that into hardhat.config.ts This is a JS type so you can add it into hardhat.config.ts as well. I guess the serialization happens after the config file is read so it your are package versionn independent :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants