Where do i find component key

Hi, I’m new to Figma and I have a design in my library. I need to get the component key so I can use it in my plugins, but I can’t find it anywhere. Thanks in advance.

Thanks, got it now. Got this error when running my pluggin.

Do you know what could be the cause?

This means the component is not published in the library.

Thanks it works now!

If you are developing a Figma plugin and need to access the component key programmatically, you can use the Figma Plugin API, specifically the key property of a ComponentNode object.

Here’s an example of how you might use it in a Figma plugin:

// Get the selected component
const selectedComponent = figma.currentPage.selection[0];

// Check if the selected node is a component
if (selectedComponent && selectedComponent.type === 'COMPONENT') {
  // Access the component key
  const componentKey = selectedComponent.key;
  console.log('Component Key:', componentKey);
} else {
  console.error('Please select a component on the canvas.');