Edit an account

Edit an account in Bitsocial React Hooks. Usage, options, and examples.

import {useAccount, setAccount, useResolvedAuthorAddress} from '@bitsocial/bitsocial-react-hooks'
const account = useAccount() // or useAccount({ accountName: 'Account KoXpxTwfnjA5' }) to use an account by name

// `account.author.wallets` only auto-generates an `eth` wallet by default.
// `account.chainProviders` is the canonical chain config for wallets, NFT lookups, and other chain reads.
// Defaults use multiple explicit Ethereum RPCs for `.eth` / `.bso` author-name resolution.
// Web defaults run a browser libp2p client and use multiple HTTP routers to discover peers.
// IPFS gateways and HTTP pubsub providers remain available as explicit account or app overrides.
// `account.nameResolversChainProviders` optionally overrides only the RPCs used for that resolution.
console.log(account.author.wallets.eth)

const ethResolverRpcUrls = [
  'https://ethereum-rpc.publicnode.com',
  'https://eth.drpc.org',
  'https://ethereum.publicnode.com',
  'https://rpc.mevblocker.io',
  'https://1rpc.io/eth',
  'https://eth-pokt.nodies.app',
]

const httpRoutersOptions = [
  'https://peers.pleb.bot',
  'https://routing.lol',
  'https://peers.forumindex.com',
  'https://peers.plebpubsub.xyz',
  'https://routerofbitsocial.xyz',
  'https://bsotracker.online',
]

const author: {...account.author, displayName: 'John'}
const editedAccount = {
  ...account,
  author,
  chainProviders: {
    ...account.chainProviders,
    eth: { urls: [...ethResolverRpcUrls, 'ethers.js'], chainId: 1 },
  },
  pkcOptions: {
    ...account.pkcOptions,
    httpRoutersOptions,
  },
  nameResolversChainProviders: {
    eth: { urls: ethResolverRpcUrls, chainId: 1 },
  },
}

await setAccount(editedAccount)

// check if the user has set their .eth or .bso author name properly, use {cache: false} or it won't update
const author = {...account.author, address: 'username.bso'} // or 'username.eth'
// authorAddress should equal to account.signer.address
const {resolvedAddress, state, error, chainProvider, nameResolver} = useResolvedAuthorAddress({author, cache: false})

// result
if (state === 'succeeded') {
  console.log('Succeeded resolving address', resolvedAddress)
}
if (state === 'failed') {
  console.log('Failed resolving address', error.message)
}

// pending
if (state === 'resolving' && nameResolver) {
  console.log(`Resolving ${nameResolver.nameSystem} address from ${nameResolver.providerLabel}`)
  console.log('Matching chain provider URLs', chainProvider?.urls)
}