Skip to content

Commit

Permalink
usdc transfer on sepolia now working
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen-Gordon committed Feb 6, 2024
1 parent e03ed92 commit 04e0d57
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
10 changes: 5 additions & 5 deletions src/GlobalRedux/Features/address/addressSlice.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
'use client'
'use client';

import { createSlice, PayloadAction } from "@reduxjs/toolkit"
import { createSlice, PayloadAction } from '@reduxjs/toolkit';

interface AddressState {
value: string;
}

const initialState: AddressState = {
value: "0xc8C26Ab40fe4723519fE66B8dBb625FC070A982c",
value: '0x6b3C5DeBB67505dfD66F3b3b80D1d24DF8DA886D',
};

const addressSlice = createSlice({
name: "address",
name: 'address',
initialState,
reducers: {
setAddress: (state, action: PayloadAction<string>) => {
Expand All @@ -21,4 +21,4 @@ const addressSlice = createSlice({
});

export const { setAddress } = addressSlice.actions;
export default addressSlice.reducer;
export default addressSlice.reducer;
23 changes: 18 additions & 5 deletions src/app/components/SendUsdc/SendUsdc.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';
// Viem
import { encodeFunctionData, parseUnits, erc20Abi } from 'viem';
import { encodeFunctionData, parseUnits, erc20Abi, parseEther } from 'viem';

// Redux
import { useSelector } from 'react-redux';
Expand Down Expand Up @@ -32,17 +32,30 @@ export default function SendUsdc() {
functionName: 'transfer',
args: [payee as `0x${string}`, parseUnits(usdcAmount, 6)],
});
console.log('Encoded:', encoded);

// Send transaction function
const sendTx = async () => {
try {
console.log('Sending USDC');
const txnHash = await kernal.sendTransaction({
to: "0x94a9D9AC8a22534E3FaCa9F4e7F2E2cf85d5E4C8", // use any address
to: usdc, // use any address
value: BigInt(0), // default to 0
data: "0x", // default to 0x
})
data: encoded, // default to 0x
});

console.log("Txn hash:", txnHash)
console.log('Txn hash:', txnHash);

const userOpHash = await kernal.sendUserOperation({
userOperation: {
callData: await kernal.account.encodeCallData({
to: usdc,
value: parseEther('0.001'),
data: encoded,
}),
},
});
console.log('User operation hash:', userOpHash);
} catch (error) {
console.log(error);
}
Expand Down

0 comments on commit 04e0d57

Please sign in to comment.