patractlabs / redspot

Redspot is an Substrate pallet-contracts (ink!) development environment. Compile your contracts and run them on a different networks. Redspot's core forks from Hardhat but changed a lot to suit substrate.
https://redspot.patract.io/
Other
67 stars 22 forks source link

Cannot sign contract unless explorer is open #156

Closed forgetso closed 2 years ago

forgetso commented 2 years ago

Redspot Version 0.13.1-0 I create a signer from my JSON file and unlock the signer if it is unlocked.

    // utility functions
    async getSigner(json_file, secrets_file) {
        const keyring = new Keyring({ss58Format: 2});
        const pair = keyring.addFromJson(json_file);
        if (pair.isLocked) {
            pair.unlock(secrets_file[json_file.address])
        }
        // network is redspot's network
        const signer = this.env.network.createSigner(pair);
        return signer
    }

I then try to create an instance of a contract.

const signedContract = contract.connect(signer)

But it fails with:

trying to sign using explorer...
explorer connection error // this makes sense as I am not running explorer

contract is previously declared by

    const contract = await contractFactory.deployed("default", deployerAddress, {
        gasLimit: "400000000000",
        value: "1000000000000 UNIT",
        salt: '0x01'
    });

How can I change the signer of the contract the account loaded from the JSON file?

ii-ii-ii commented 2 years ago

redspot does have this problem when using explorer. Custom accounts are not supported now, you can generate accounts via suri in the redspot account config. Or use polkadot extension to sign. Or just close the redspot explorer.

But,this is indeed a problem, and we will improve the account import later.

forgetso commented 2 years ago

Thanks for the tip. It seems that that I can get it to work using the redspot signer object instead of my own one.

        // this.env.network = redspot network 
        const pair = this.env.network.keyring.addFromJson(json_file);

        if (pair.isLocked) {
            pair.unlock(secrets_file[json_file.address])
        }
        const signer = this.env.network.createSigner(pair);