ChainName
This component fetches then shows the name of a chain.
It inherits all the attributes of a HTML <span>
component, hence you can style it just like how you would style a normal <span>
import { ChainProvider, ChainName } from "thirdweb/react";import { ethereum } from "thirdweb/chains"; <ChainProvider {...props}> <ChainName /></ChainProvider>;
Result:
<span>Ethereum Mainnet</span>
By default ChainName will call the thirdweb API to retrieve the chain name.
However if you have a different way to fetch the name, you can pass the function to the nameResolver
prop.
Note: nameResolver should either be a string or a function (async) that returns a string.
async function fetchNameMethod() { // your own fetching logic return "the chain name";} <ChainName nameResolver={fetchNameMethod} />;
Alternatively you can also pass in a string directly:
<ChainName nameResolver="ETH Mainnet" />;
The ChainName component accepts a formatFn
which takes in a string and outputs a string
The function is used to modify the name of the chain
const concatStr = (str: string):string => str + "Network" <ChainProvider {...props}> <ChainName formatFn={concatStr} /></ChainProvider>
Result:
<span>Ethereum Mainnet Network</span>
import { ChainProvider, ChainName } from "thirdweb/react"; <ChainProvider {...props}> <ChainName loadingComponent={<Spinner />} /></ChainProvider>;
<ChainProvider {...props}> <ChainName fallbackComponent={"Failed to load"} /></ChainProvider>;
This component uses @tanstack-query
's useQuery internally.
You can use the queryOptions
prop for more fine-grained control
<ChainName queryOptions={{ enabled: isEnabled, retry: 4, }}/>;
let __namedParameters: {about : string,accessKey : string,aria-activedescendant : string,aria-atomic : Booleanish,aria-autocomplete : "inline" | "none" | "list" | "both",aria-braillelabel : string,aria-brailleroledescription : string,aria-busy : Booleanish,aria-checked : boolean | "false" | "true" | "mixed",aria-colcount : number,aria-colindex : number,aria-colindextext : string,aria-colspan : number,aria-controls : string,aria-current : boolean | "false" | "true" | "time" | "step" | "page" | "location" | "date",aria-describedby : string,aria-description : string,aria-details : string,aria-disabled : Booleanish,aria-dropeffect : "link" | "popup" | "none" | "execute" | "copy" | "move",aria-errormessage : string,aria-expanded : Booleanish,aria-flowto : string,aria-grabbed : Booleanish,aria-haspopup : boolean | "false" | "true" | "dialog" | "menu" | "grid" | "tree" | "listbox",aria-hidden : Booleanish,aria-invalid : boolean | "false" | "true" | "grammar" | "spelling",aria-keyshortcuts : string,aria-label : string,aria-labelledby : string,aria-level : number,aria-live : "off" | "polite" | "assertive",aria-modal : Booleanish,aria-multiline : Booleanish,aria-multiselectable : Booleanish,aria-orientation : "horizontal" | "vertical",aria-owns : string,aria-placeholder : string,aria-posinset : number,aria-pressed : boolean | "false" | "true" | "mixed",aria-readonly : Booleanish,aria-relevant : "text" | "all" | "additions" | "additions removals" | "additions text" | "removals" | "removals additions" | "removals text" | "text additions" | "text removals",aria-required : Booleanish,aria-roledescription : string,aria-rowcount : number,aria-rowindex : number,aria-rowindextext : string,aria-rowspan : number,aria-selected : Booleanish,aria-setsize : number,aria-sort : "none" | "ascending" | "descending" | "other",aria-valuemax : number,aria-valuemin : number,aria-valuenow : number,aria-valuetext : string,autoCapitalize : (string & ({ })) | "on" | "off" | "none" | "sentences" | "words" | "characters",autoCorrect : string,autoFocus : boolean,autoSave : string,className : string,color : string,content : string,contentEditable : "inherit" | (Booleanish) | "plaintext-only",contextMenu : string,dangerouslySetInnerHTML : { __html: string | (TrustedHTML) },datatype : string,defaultChecked : boolean,defaultValue : string | number | (readonly Array<string>),dir : string,draggable : Booleanish,enterKeyHint : "search" | "done" | "next" | "send" | "enter" | "go" | "previous",fallbackComponent : Element,formatFn : (str: string) => string,hidden : boolean,id : string,inert : boolean,inlist : any,inputMode : "search" | "email" | "url" | "text" | "none" | "tel" | "numeric" | "decimal",is : string,itemID : string,itemProp : string,itemRef : string,itemScope : boolean,itemType : string,lang : string,loadingComponent : Element,nameResolver : string | (() => string) | (() => Promise<string>),nonce : string,onAbort : ReactEventHandler<HTMLSpanElement>,onAbortCapture : ReactEventHandler<HTMLSpanElement>,onAnimationEnd : AnimationEventHandler<HTMLSpanElement>,onAnimationEndCapture : AnimationEventHandler<HTMLSpanElement>,onAnimationIteration : AnimationEventHandler<HTMLSpanElement>,onAnimationIterationCapture : AnimationEventHandler<HTMLSpanElement>,onAnimationStart : AnimationEventHandler<HTMLSpanElement>,onAnimationStartCapture : AnimationEventHandler<HTMLSpanElement>,onAuxClick : MouseEventHandler<HTMLSpanElement>,onAuxClickCapture : MouseEventHandler<HTMLSpanElement>,onBeforeInput : FormEventHandler<HTMLSpanElement>,onBeforeInputCapture : FormEventHandler<HTMLSpanElement>,onBeforeToggle : ToggleEventHandler<HTMLSpanElement>,onBlur : FocusEventHandler<HTMLSpanElement>,onBlurCapture : FocusEventHandler<HTMLSpanElement>,onCanPlay : ReactEventHandler<HTMLSpanElement>,onCanPlayCapture : ReactEventHandler<HTMLSpanElement>,onCanPlayThrough : ReactEventHandler<HTMLSpanElement>,onCanPlayThroughCapture : ReactEventHandler<HTMLSpanElement>,onChange : FormEventHandler<HTMLSpanElement>,onChangeCapture : FormEventHandler<HTMLSpanElement>,onClick : MouseEventHandler<HTMLSpanElement>,onClickCapture : MouseEventHandler<HTMLSpanElement>,onCompositionEnd : CompositionEventHandler<HTMLSpanElement>,onCompositionEndCapture : CompositionEventHandler<HTMLSpanElement>,onCompositionStart : CompositionEventHandler<HTMLSpanElement>,onCompositionStartCapture : CompositionEventHandler<HTMLSpanElement>,onCompositionUpdate : CompositionEventHandler<HTMLSpanElement>,onCompositionUpdateCapture : CompositionEventHandler<HTMLSpanElement>,onContextMenu : MouseEventHandler<HTMLSpanElement>,onContextMenuCapture : MouseEventHandler<HTMLSpanElement>,onCopy : ClipboardEventHandler<HTMLSpanElement>,onCopyCapture : ClipboardEventHandler<HTMLSpanElement>,onCut : ClipboardEventHandler<HTMLSpanElement>,onCutCapture : ClipboardEventHandler<HTMLSpanElement>,onDoubleClick : MouseEventHandler<HTMLSpanElement>,onDoubleClickCapture : MouseEventHandler<HTMLSpanElement>,onDrag : DragEventHandler<HTMLSpanElement>,onDragCapture : DragEventHandler<HTMLSpanElement>,onDragEnd : DragEventHandler<HTMLSpanElement>,onDragEndCapture : DragEventHandler<HTMLSpanElement>,onDragEnter : DragEventHandler<HTMLSpanElement>,onDragEnterCapture : DragEventHandler<HTMLSpanElement>,onDragExit : DragEventHandler<HTMLSpanElement>,onDragExitCapture : DragEventHandler<HTMLSpanElement>,onDragLeave : DragEventHandler<HTMLSpanElement>,onDragLeaveCapture : DragEventHandler<HTMLSpanElement>,onDragOver : DragEventHandler<HTMLSpanElement>,onDragOverCapture : DragEventHandler<HTMLSpanElement>,onDragStart : DragEventHandler<HTMLSpanElement>,onDragStartCapture : DragEventHandler<HTMLSpanElement>,onDrop : DragEventHandler<HTMLSpanElement>,onDropCapture : DragEventHandler<HTMLSpanElement>,onDurationChange : ReactEventHandler<HTMLSpanElement>,onDurationChangeCapture : ReactEventHandler<HTMLSpanElement>,onEmptied : ReactEventHandler<HTMLSpanElement>,onEmptiedCapture : ReactEventHandler<HTMLSpanElement>,onEncrypted : ReactEventHandler<HTMLSpanElement>,onEncryptedCapture : ReactEventHandler<HTMLSpanElement>,onEnded : ReactEventHandler<HTMLSpanElement>,onEndedCapture : ReactEventHandler<HTMLSpanElement>,onError : ReactEventHandler<HTMLSpanElement>,onErrorCapture : ReactEventHandler<HTMLSpanElement>,onFocus : FocusEventHandler<HTMLSpanElement>,onFocusCapture : FocusEventHandler<HTMLSpanElement>,onGotPointerCapture : PointerEventHandler<HTMLSpanElement>,onGotPointerCaptureCapture : PointerEventHandler<HTMLSpanElement>,onInput : FormEventHandler<HTMLSpanElement>,onInputCapture : FormEventHandler<HTMLSpanElement>,onInvalid : FormEventHandler<HTMLSpanElement>,onInvalidCapture : FormEventHandler<HTMLSpanElement>,onKeyDown : KeyboardEventHandler<HTMLSpanElement>,onKeyDownCapture : KeyboardEventHandler<HTMLSpanElement>,onKeyPress : KeyboardEventHandler<HTMLSpanElement>,onKeyPressCapture : KeyboardEventHandler<HTMLSpanElement>,onKeyUp : KeyboardEventHandler<HTMLSpanElement>,onKeyUpCapture : KeyboardEventHandler<HTMLSpanElement>,onLoad : ReactEventHandler<HTMLSpanElement>,onLoadCapture : ReactEventHandler<HTMLSpanElement>,onLoadedData : ReactEventHandler<HTMLSpanElement>,onLoadedDataCapture : ReactEventHandler<HTMLSpanElement>,onLoadedMetadata : ReactEventHandler<HTMLSpanElement>,onLoadedMetadataCapture : ReactEventHandler<HTMLSpanElement>,onLoadStart : ReactEventHandler<HTMLSpanElement>,onLoadStartCapture : ReactEventHandler<HTMLSpanElement>,onLostPointerCapture : PointerEventHandler<HTMLSpanElement>,onLostPointerCaptureCapture : PointerEventHandler<HTMLSpanElement>,onMouseDown : MouseEventHandler<HTMLSpanElement>,onMouseDownCapture : MouseEventHandler<HTMLSpanElement>,onMouseEnter : MouseEventHandler<HTMLSpanElement>,onMouseLeave : MouseEventHandler<HTMLSpanElement>,onMouseMove : MouseEventHandler<HTMLSpanElement>,onMouseMoveCapture : MouseEventHandler<HTMLSpanElement>,onMouseOut : MouseEventHandler<HTMLSpanElement>,onMouseOutCapture : MouseEventHandler<HTMLSpanElement>,onMouseOver : MouseEventHandler<HTMLSpanElement>,onMouseOverCapture : MouseEventHandler<HTMLSpanElement>,onMouseUp : MouseEventHandler<HTMLSpanElement>,onMouseUpCapture : MouseEventHandler<HTMLSpanElement>,onPaste : ClipboardEventHandler<HTMLSpanElement>,onPasteCapture : ClipboardEventHandler<HTMLSpanElement>,onPause : ReactEventHandler<HTMLSpanElement>,onPauseCapture : ReactEventHandler<HTMLSpanElement>,onPlay : ReactEventHandler<HTMLSpanElement>,onPlayCapture : ReactEventHandler<HTMLSpanElement>,onPlaying : ReactEventHandler<HTMLSpanElement>,onPlayingCapture : ReactEventHandler<HTMLSpanElement>,onPointerCancel : PointerEventHandler<HTMLSpanElement>,onPointerCancelCapture : PointerEventHandler<HTMLSpanElement>,onPointerDown : PointerEventHandler<HTMLSpanElement>,onPointerDownCapture : PointerEventHandler<HTMLSpanElement>,onPointerEnter : PointerEventHandler<HTMLSpanElement>,onPointerLeave : PointerEventHandler<HTMLSpanElement>,onPointerMove : PointerEventHandler<HTMLSpanElement>,onPointerMoveCapture : PointerEventHandler<HTMLSpanElement>,onPointerOut : PointerEventHandler<HTMLSpanElement>,onPointerOutCapture : PointerEventHandler<HTMLSpanElement>,onPointerOver : PointerEventHandler<HTMLSpanElement>,onPointerOverCapture : PointerEventHandler<HTMLSpanElement>,onPointerUp : PointerEventHandler<HTMLSpanElement>,onPointerUpCapture : PointerEventHandler<HTMLSpanElement>,onProgress : ReactEventHandler<HTMLSpanElement>,onProgressCapture : ReactEventHandler<HTMLSpanElement>,onRateChange : ReactEventHandler<HTMLSpanElement>,onRateChangeCapture : ReactEventHandler<HTMLSpanElement>,onReset : FormEventHandler<HTMLSpanElement>,onResetCapture : FormEventHandler<HTMLSpanElement>,onResize : ReactEventHandler<HTMLSpanElement>,onResizeCapture : ReactEventHandler<HTMLSpanElement>,onScroll : UIEventHandler<HTMLSpanElement>,onScrollCapture : UIEventHandler<HTMLSpanElement>,onSeeked : ReactEventHandler<HTMLSpanElement>,onSeekedCapture : ReactEventHandler<HTMLSpanElement>,onSeeking : ReactEventHandler<HTMLSpanElement>,onSeekingCapture : ReactEventHandler<HTMLSpanElement>,onSelect : ReactEventHandler<HTMLSpanElement>,onSelectCapture : ReactEventHandler<HTMLSpanElement>,onStalled : ReactEventHandler<HTMLSpanElement>,onStalledCapture : ReactEventHandler<HTMLSpanElement>,onSubmit : FormEventHandler<HTMLSpanElement>,onSubmitCapture : FormEventHandler<HTMLSpanElement>,onSuspend : ReactEventHandler<HTMLSpanElement>,onSuspendCapture : ReactEventHandler<HTMLSpanElement>,onTimeUpdate : ReactEventHandler<HTMLSpanElement>,onTimeUpdateCapture : ReactEventHandler<HTMLSpanElement>,onToggle : ToggleEventHandler<HTMLSpanElement>,onTouchCancel : TouchEventHandler<HTMLSpanElement>,onTouchCancelCapture : TouchEventHandler<HTMLSpanElement>,onTouchEnd : TouchEventHandler<HTMLSpanElement>,onTouchEndCapture : TouchEventHandler<HTMLSpanElement>,onTouchMove : TouchEventHandler<HTMLSpanElement>,onTouchMoveCapture : TouchEventHandler<HTMLSpanElement>,onTouchStart : TouchEventHandler<HTMLSpanElement>,onTouchStartCapture : TouchEventHandler<HTMLSpanElement>,onTransitionCancel : TransitionEventHandler<HTMLSpanElement>,onTransitionCancelCapture : TransitionEventHandler<HTMLSpanElement>,onTransitionEnd : TransitionEventHandler<HTMLSpanElement>,onTransitionEndCapture : TransitionEventHandler<HTMLSpanElement>,onTransitionRun : TransitionEventHandler<HTMLSpanElement>,onTransitionRunCapture : TransitionEventHandler<HTMLSpanElement>,onTransitionStart : TransitionEventHandler<HTMLSpanElement>,onTransitionStartCapture : TransitionEventHandler<HTMLSpanElement>,onVolumeChange : ReactEventHandler<HTMLSpanElement>,onVolumeChangeCapture : ReactEventHandler<HTMLSpanElement>,onWaiting : ReactEventHandler<HTMLSpanElement>,onWaitingCapture : ReactEventHandler<HTMLSpanElement>,onWheel : WheelEventHandler<HTMLSpanElement>,onWheelCapture : WheelEventHandler<HTMLSpanElement>,popover : "" | "auto" | "manual",popoverTarget : string,popoverTargetAction : "toggle" | "hide" | "show",prefix : string,property : string,queryOptions : Omit<UseQueryOptions<string, Error, string, QueryKey>, "queryKey" | "queryFn">,radioGroup : string,rel : string,resource : string,results : number,rev : string,role : AriaRole,security : string,slot : string,spellCheck : Booleanish,style : CSSProperties,suppressContentEditableWarning : boolean,suppressHydrationWarning : boolean,tabIndex : number,title : string,translate : "yes" | "no",typeof : string,unselectable : "on" | "off",vocab : string}