@abstract-foundation/agw-client
Version:
Abstract Global Wallet Client SDK
40 lines • 1.77 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.deployAccount = deployAccount;
const viem_1 = require("viem");
const AccountFactory_js_1 = require("../abis/AccountFactory.js");
const constants_js_1 = require("../constants.js");
const utils_js_1 = require("../utils.js");
async function deployAccount(params) {
const { initialSignerAddress, walletClient, publicClient, ...rest } = params;
const initialSigner = initialSignerAddress ?? walletClient.account.address;
const address = await (0, utils_js_1.getSmartAccountAddressFromInitialSigner)(initialSigner, publicClient);
let deploymentTransaction = undefined;
const isDeployed = await (0, utils_js_1.isSmartAccountDeployed)(publicClient, address);
if (!isDeployed) {
const initializerCallData = (0, utils_js_1.getInitializerCalldata)(initialSigner, constants_js_1.EOA_VALIDATOR_ADDRESS, {
allowFailure: false,
callData: '0x',
value: 0n,
target: viem_1.zeroAddress,
});
const addressBytes = (0, viem_1.toBytes)(initialSigner);
const salt = (0, viem_1.keccak256)(addressBytes);
const deploymentCalldata = (0, viem_1.encodeFunctionData)({
abi: AccountFactory_js_1.default,
functionName: 'deployAccount',
args: [salt, initializerCallData],
});
deploymentTransaction = await walletClient.sendTransaction({
account: walletClient.account,
to: constants_js_1.SMART_ACCOUNT_FACTORY_ADDRESS,
data: deploymentCalldata,
...rest,
});
}
return {
smartAccountAddress: address,
deploymentTransaction,
};
}
//# sourceMappingURL=deployAccount.js.map