const { sepolia } = require("viem/chains")
const {
ChainId,
FireblocksWeb3Provider,
ApiBaseUrl
} = require("@fireblocks/fireblocks-web3-provider")
const {
createWalletClient,
custom,
createPublicClient,
http
} = require("viem")
// Import the Sepolia USDC ABI
const ABI = require("./USDC_SEPOLIA_ABI.json");
// Sepolia USDC Contract Address
const CONTRACT_ADDRESS = '0x94a9d9ac8a22534e3faca9f4e7f2e2cf85d5e4c8'
(async () => {
const spenderAddr = "<spender_addr>";
// 1 USDC to approve
const amount = 1e6;
const eip1193Provider = new FireblocksWeb3Provider({
// apiBaseUrl: ApiBaseUrl.Sandbox, // If using a sandbox workspace
privateKey: process.env.FIREBLOCKS_API_PRIVATE_KEY_PATH,
apiKey: process.env.FIREBLOCKS_API_KEY,
vaultAccountIds: process.env.FIREBLOCKS_VAULT_ACCOUNT_IDS,
chainId: ChainId.SEPOLIA
});
// Create wallet client instance
const walletClient = createWalletClient({
chain: sepolia,
transport: custom(eip1193Provider),
});
// Create public client instance
const publicClient = createPublicClient({
chain: sepolia,
transport: http()
})
// Get my account's address
const [ account ] = await walletClient.getAddresses();
// Simulate the 'approve' call
const { request } = await publicClient.simulateContract({
address: CONTRACT_ADDRESS,
abi: ABI,
functionName: 'approve',
args: [spenderAddr, amount],
account
})
// Execute approve call via Fireblocks
await walletClient.writeContract(request)
})();