hardhat
Version:
Hardhat is an extensible developer tool that helps smart contract developers increase productivity by reliably bringing together the tools they want.
24 lines • 1.16 kB
JavaScript
import { assertHardhatInvariant } from "@nomicfoundation/hardhat-errors";
import { SenderHandler } from "./sender.js";
/**
* This class automatically retrieves and caches the first available account from the connected provider.
* It overrides the getSender method of the base class to request the list of accounts if the first account has not been fetched yet,
* ensuring dynamic selection of the sender for all JSON-RPC requests without requiring manual input.
*/
export class AutomaticSenderHandler extends SenderHandler {
async getSender() {
if (this.
const accounts = await this.provider.request({
method: "eth_accounts",
});
// TODO: This shouldn't be an exception but a failed JSON response!
assertHardhatInvariant(Array.isArray(accounts), "eth_accounts response should be an array");
this.
this.
}
return this.
}
}
//# sourceMappingURL=automatic-sender-handler.js.map