Skip to content

Commit

Permalink
auto-add 0x prefix for private key and use `prepareTransactionReque…
Browse files Browse the repository at this point in the history
…st` instead of `simulateContract`
  • Loading branch information
talentlessguy committed Nov 7, 2023
1 parent 8364b82 commit 416eb47
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 27 deletions.
13 changes: 3 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
"version": "0.1.1",
"description": "🌸 Self-custodial decentralized deployments",
"type": "module",
"bin": {
"blumen": "./dist/cli.js"
},
"bin": { "blumen": "./dist/cli.js" },
"exports": "./dist/index.js",
"types": "./dist/index.d.ts",
"repository": {
Expand All @@ -20,18 +18,13 @@
"prepublishOnly": "pnpm build"
},
"keywords": [
"ipfs",
"filecoin",
"deploy",
"cli"
"ipfs", "filecoin", "deploy", "cli"
],
"files": [
"dist"
],
"author": "v1rtl <[email protected]>",
"engines": {
"node": ">=16.8"
},
"engines": { "node": ">=16.8" },
"license": "MIT",
"dependencies": {
"@ensdomains/content-hash": "^3.0.0",
Expand Down
33 changes: 16 additions & 17 deletions src/actions/ens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const ensAction = async (

if (!pk) throw new MissingKeyError('PK')

const account = privateKeyToAccount(pk as `0x${string}`)
const account = privateKeyToAccount(pk.startsWith('0x') ? pk as `0x${string}` : `0x${pk}`)

const walletClient = createWalletClient({
transport: http(),
Expand All @@ -65,31 +65,30 @@ export const ensAction = async (

logger.info(`Validating transaction for wallet ${account.address}`)

const { request } = await publicClient.simulateContract({
abi,
functionName: 'setContenthash',
account: safeAddress ? getEip3770Address({ fullAddress: safeAddress, chainId: chain.id }).address : account.address,
address: PUBLIC_RESOLVER_ADDRESS[chain.id as 1 | 5],
args: [node, `0x${contentHash}`],
chain
const from = safeAddress ? getEip3770Address({ fullAddress: safeAddress, chainId: chain.id }).address : account.address

const request = await publicClient.prepareTransactionRequest({
account: from,
to: PUBLIC_RESOLVER_ADDRESS[chain.id as 1 | 5],
chain,
data: encodeFunctionData({
functionName: 'setContenthash',
abi,
args: [node, `0x${contentHash}`]
})
})

if (safeAddress) {
logger.info(`Preparing a transaction for Safe ${safeAddress}`)
const safeWalletClient = walletClient.extend(walletSafeActions(safeAddress))
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore

const safePublicClient = publicClient.extend(publicSafeActions(safeAddress))

const nonce = await safePublicClient.getSafeNonce()

const txData = {
to: request.address,
data: encodeFunctionData({
functionName: 'setContenthash',
abi,
args: [node, `0x${contentHash}`]
}),
...request,
to: request.to as Address,
operation: operationType ?? OperationType.Call,
gasPrice: request.gasPrice ?? 0n,
nonce
Expand Down Expand Up @@ -132,7 +131,7 @@ export const ensAction = async (
let hash: Hash = '0x'

try {
hash = await walletClient.writeContract(request)
hash = await walletClient.sendTransaction(request)
} catch (e) {
if (e instanceof TransactionExecutionError) {
if (e.details?.includes('insufficient funds')) {
Expand Down

0 comments on commit 416eb47

Please sign in to comment.