Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove unneccessary bundler initialization call #19

Merged
merged 3 commits into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.1.1

* Remove chainId verification in the bundler provider
* Allow entrypoint v0.7 for any bundler

## 0.1.0

* Training wheel support for entrypoint v0.7.0 via pimlico bundler
Expand Down
54 changes: 37 additions & 17 deletions example/lib/providers/wallet_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,18 @@ class WalletProvider extends ChangeNotifier {

WalletProvider()
: _chain = Chain(
chainId: 11155111,
chainId: 31337,
explorer: "https://sepolia.etherscan.io/",
entrypoint: EntryPointAddress.v07)
entrypoint: EntryPointAddress(
0.6,
EthereumAddress.fromHex(
"0x5165c9e79213e2208947589c6e1dcc80ee8d3d00")))
..accountFactory = EthereumAddress.fromHex(
"0xECA49857B32A12403F5a3A64ad291861EF4B63cb") // v07 p256 factory address
..jsonRpcUrl = "https://rpc.ankr.com/eth_sepolia"
..bundlerUrl =
"https://api.pimlico.io/v2/11155111/rpc?apikey=YOUR_API_KEY"
..paymasterUrl =
"https://api.pimlico.io/v2/11155111/rpc?apikey=YOUR_API_KEY";
"0x0ce83Bf5d20c539E77e1E607B8349E26c6b20133") // v07 p256 factory address
..jsonRpcUrl = "http://127.0.0.1:8545"
..bundlerUrl = "http://localhost:3000/rpc";
// ..paymasterUrl =
// "https://api.pimlico.io/v2/11155111/rpc?apikey=875f3458-a37c-4187-8ac5-d08bbfa0d501";

// "0x402A266e92993EbF04a5B3fd6F0e2b21bFC83070" v06 p256 factory address
Future<void> registerWithPassKey(String name,
Expand All @@ -45,7 +47,8 @@ class WalletProvider extends ChangeNotifier {
PassKeySigner("webauthn.io", "webauthn", "https://webauthn.io");
final hwdSigner = HardwareSigner.withTag(name);

final salt = Uint256.fromHex(
final salt = Uint256.zero;
Uint256.fromHex(
hexlify(w3d.keccak256(Uint8List.fromList(utf8.encode(name)))));

try {
Expand Down Expand Up @@ -93,21 +96,23 @@ class WalletProvider extends ChangeNotifier {
}

Future<void> createPrivateKeyWallet() async {
_chain.accountFactory = Constants.simpleAccountFactoryAddressv06;
final random = math.Random.secure();
final privateKey = EthPrivateKey.createRandom(random);

final signer = PrivateKeySigner.createRandom("123456");
final signer = PrivateKeySigner.create(privateKey, "123456", random);
log("signer: ${signer.getAddress()}");
log("pk: ${hexlify(privateKey.privateKey)}");

final SmartWalletFactory walletFactory = SmartWalletFactory(_chain, signer);

final salt = Uint256.fromHex(hexlify(w3d
.keccak256(EthereumAddress.fromHex(signer.getAddress()).addressBytes)));

log("salt: ${salt.toHex()}");
log("pk salt: ${salt.toHex()}");

try {
_wallet = await walletFactory.createSimpleAccount(salt);
log("wallet created ${_wallet?.address.hex} ");
log("pk wallet created ${_wallet?.address.hex} ");
} catch (e) {
_errorMessage = e.toString();
notifyListeners();
Expand Down Expand Up @@ -146,6 +151,7 @@ class WalletProvider extends ChangeNotifier {
userDefinedMaxPriorityFeePerGas: BigInt.parse("0x52412100"));
}
// mints nft
log(DateTime.timestamp().toString());
final tx1 = await _wallet?.sendTransaction(
nft,
Contract.encodeFunctionCall("safeMint", nft,
Expand Down Expand Up @@ -174,16 +180,30 @@ class WalletProvider extends ChangeNotifier {

Future<void> sendTransaction(String recipient, String amount) async {
if (_wallet != null) {
final etherAmount = w3d.EtherAmount.fromBigInt(w3d.EtherUnit.wei,
BigInt.from(double.parse(amount) * math.pow(10, 18)));
final response = await transferToken(
EthereumAddress.fromHex(recipient),
w3d.EtherAmount.fromBigInt(
w3d.EtherUnit.wei, BigInt.from(20 * math.pow(10, 6))));

// final etherAmount = w3d.EtherAmount.fromBigInt(w3d.EtherUnit.wei,
// BigInt.from(double.parse(amount) * math.pow(10, 18)));

final response =
await _wallet?.send(EthereumAddress.fromHex(recipient), etherAmount);
// final response =
// await _wallet?.send(EthereumAddress.fromHex(recipient), etherAmount);
final receipt = await response?.wait();

log("Transaction receipt Hash: ${receipt?.userOpHash}");
} else {
log("No wallet available to send transaction");
}
}

Future<UserOperationResponse?> transferToken(
EthereumAddress recipient, w3d.EtherAmount amount) async {
final erc20 =
EthereumAddress.fromHex("0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9");

return await _wallet?.sendTransaction(
erc20, Contract.encodeERC20TransferCall(erc20, recipient, amount));
}
}
4 changes: 3 additions & 1 deletion example/lib/screens/create_account.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ class _CreateAccountScreenState extends State<CreateAccountScreen> {
child: TextButton.icon(
onPressed: () {
try {
context.read<WalletProvider>().createSafeWallet();
context
.read<WalletProvider>()
.createPrivateKeyWallet();
Navigator.pushNamed(context, '/home');
} catch (e) {
'Something went wrong: $e';
Expand Down
Loading
Loading