-
In 7:47:25, Patrick used connect() method to show us how the encrypted key can be used. But why did we need this? The initial code we had didn't have to use connect() method Using encrypted private key const encryptedJson = fs.readFileSync("./encrypted.json", "utf8");
let wallet = new ethers.Wallet.fromEncryptedJsonSync(
encryptedJson,
process.env.PSW
);
wallet = await wallet.connect(provider); VS We didn't use connect() method here in our initial code const provider = new ethers.providers.JsonRpcProvider(process.env.RPC_URL);
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY, provider);
const abi = fs.readFileSync("./SimpleStorage_sol_SimpleStorage.abi", "utf8");
const bin = fs.readFileSync("./SImpleStorage_sol_SimpleStorage.bin", "utf8");
const contractFactory = new ethers.ContractFactory(abi, bin, wallet); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
It is so that our instance of the decrypted wallet here
can then be instead used to get an instance of the new wallet; which—in this case—is the same decrypted wallet but connected to the provider you provide. From docs: "Creates a new Wallet instance from an existing instance, connected to a new provider." "A connected Provider which allows the wallet to connect to the Ethereum network to query its state and send transactions, or null if no provider is connected. To change the provider, use the connect method, which will return a new instance of the Wallet connected to the provider." Entire read: https://docs.ethers.io/v4/api-wallet.html |
Beta Was this translation helpful? Give feedback.
It is so that our instance of the decrypted wallet here
can then be instead used to get an instance of the new wallet; which—in this case—is the same decrypted wallet but connected to the provider you provide.
From docs:
"Creates a new Wallet instance from an existing instance, connected to a new provider."
"A connected Provider which allows the wallet to connect to the Ethereum network to query its state and send transactions, or null if no provider is connected.
To change the provider, use the connect method, which will return a new instance of the Wallet connected to the provider."
Entire…