Hello,
I am trying to slice a user’s address once they authenticate into the dapp, the way metamask does it.
example address: 0x55555555555555555555555555555555555557890
slice it to show on front end : 0x555…7890
Thank you
Hello,
I am trying to slice a user’s address once they authenticate into the dapp, the way metamask does it.
example address: 0x55555555555555555555555555555555555557890
slice it to show on front end : 0x555…7890
Thank you
You can use this -
Or write this function and pass in the address string–
const getEllipsisTxt = (str, n = 6) => {
if (str) {
return `${str.slice(0, n)}...${str.slice(str.length - n)}`;
}
return "";
};
Gold, worked. thanks brother
You could just use .slice(-6)
const userAddress = await window.ethereum.request({ method: 'eth_requestAccounts' });
let userColour = '#' + userAddress[0].slice(-6);
console.log(userColour);