Skip to content

Commit

Permalink
Merge pull request #15 from cfluke-cb/cfluke/move-env
Browse files Browse the repository at this point in the history
Cfluke/move env
  • Loading branch information
chunter-cb authored Mar 18, 2024
2 parents c866c18 + b89992f commit dc78047
Show file tree
Hide file tree
Showing 17 changed files with 111 additions and 67 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
RPC_URL='YOUR_RPC_URL'
PRIVATE_KEY='YOUR_PRIVATE_KEY'
ACCOUNT_TYPE='simple' # simple, safe, kernel
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
examples/*/node_modules/
examples/*/yarn-error.log
examples/*/yarn-error.log

.env
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,27 @@ git clone https://github.com/coinbase/paymaster-bundler-examples.git

### 2. Set up environment variables

- ### Copy the env example

```
cp .env.example .env
```

- ### Install dotenv

```
yarn
```

- This will setup dotenv to load the env file for private values

- ### Create your Base Node RPC URL

- Navigate to https://coinbase.com/cloud/products/base/rpc
- Sign up for a Coinbase Cloud account, if you don't have one already
- Create a project, and select **Base Sepolia**
- Click "**Activate**" on the Paymaster & Bundler modal
- Copy your RPC endpoint, and paste it into `config.json` as the `rpc_url` variable.
- Copy your RPC endpoint, and paste it into `.env` as the `RPC_URL` variable.

- ### Add a signer

Expand All @@ -52,11 +66,11 @@ git clone https://github.com/coinbase/paymaster-bundler-examples.git
- You can create a new private key with [Foundry](https://book.getfoundry.sh/reference/cast/cast-wallet-new)
- To install Foundry, run `curl -L https://foundry.paradigm.xyz | bash`
- To generate a new key pair, run `cast wallet new`
- Copy your private key, and paste it into `config.json` as the `private_key` variable
- Copy your private key, and paste it into `.env` as the `PRIVATE_KEY` variable

- ### Optional: configure the smart account for Pimlico

- If you're using Pimlico, you can use a different smart account type by changing the `account_type` variable in `config.json`
- If you're using Pimlico, you can use a different smart account type by changing the `account_type` variable in `.env`
- Valid values: `simple`, `safe`, `kernel`
- [pimlico/src/account.js](https://github.com/coinbase/paymaster-bundler-examples/blob/master/examples/pimlico/src/account.js) is a code example on how to configure a different smart account for SDKs that support this feature

Expand Down
13 changes: 13 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import dotenv from 'dotenv'

// Updating path due to being executed in the examples/x directory
dotenv.config({ path: '../../.env' })

export default {
"rpc_url": process.env.RPC_URL,
"private_key": process.env.PRIVATE_KEY,
"account_type": process.env.ACCOUNT_TYPE || 'simple',
"contract_address": "0x66519FCAee1Ed65bc9e0aCc25cCD900668D3eD49",
"function_name": "mintTo",
"entry_point": "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789"
}
8 changes: 0 additions & 8 deletions config.json

This file was deleted.

2 changes: 1 addition & 1 deletion examples/alchemy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
"dev": "node src/mint.js"
},
"type": "module"
}
}
2 changes: 1 addition & 1 deletion examples/alchemy/src/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createLightAccount } from "@alchemy/aa-accounts";
import { LocalAccountSigner } from "@alchemy/aa-core";
import { baseSepolia } from 'viem/chains';
import { transport } from "./utils.js";
import config from '../../../config.json' assert { type: 'json' };
import config from '../../../config.js';

// Create the signer
// To customize the signer, see https://accountkit.alchemy.com/signers/choosing-a-signer.html
Expand Down
8 changes: 5 additions & 3 deletions examples/alchemy/src/mint.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { sponsorUserOperation, updateUserOpGasFields } from "./paymaster.js";
import { abi } from "./abi.js";
import { account } from "./account.js"
import { extractHashFromError, transport } from "./utils.js"
import config from '../../../config.json' assert { type: 'json' };
import config from '../../../config.js';

// Create the smart account for the user
const smartAccountClient = createSmartAccountClient({
Expand All @@ -32,7 +32,7 @@ const smartAccountClient = createSmartAccountClient({
dummyPaymasterAndData: () => "0x",
},
});
console.log("\x1b[33m%s\x1b[0m", `Minting to ${smartAccountClient.account.address} (Account type: simple)`);
console.log("\x1b[33m%s\x1b[0m", `Minting to ${smartAccountClient.account.address} (Account type: ${config.account_type})`);

// Encode the calldata
const callData = encodeFunctionData({
Expand All @@ -46,9 +46,11 @@ console.log("Waiting for transaction...")
// Send the sponsored transaction!
const uo = await smartAccountClient.sendUserOperation({
uo: { target: contractAddress, data: callData, value: BigInt(0) },
//uo: { target: '0x0000000000000000000000000000000000000000', data: '0x', value: BigInt(0) },
});
try {
await smartAccountClient.waitForUserOperationTransaction(uo);
const tx = await smartAccountClient.waitForUserOperationTransaction(uo);
console.log(tx)
} catch (error) {
// There's currently an issue with viem not being able to find the transaction hash, but it does exist
const txHash = extractHashFromError(error.toString())
Expand Down
2 changes: 1 addition & 1 deletion examples/alchemy/src/paymaster.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

import { deepHexlify, resolveProperties } from "@alchemy/aa-core";
import axios from "axios";
import config from '../../../config.json' assert { type: 'json' };
import config from '../../../config.js';

const paymasterRequest = (userOp, opts) => {
return {
Expand Down
2 changes: 1 addition & 1 deletion examples/alchemy/src/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { http } from "viem";
import config from '../../../config.json' assert { type: 'json' };
import config from '../../../config.js';

export const extractHashFromError = (errorString) => {
const regex = /Transaction with hash "([^"]+)"/;
Expand Down
Loading

0 comments on commit dc78047

Please sign in to comment.