import * as PeerId from '@tevm/voltaire/PeerId'
// Add peer via admin_addPeer
async function addPeer(rpcUrl: string, enodeUrl: string): Promise<boolean> {
const peerId = PeerId.from(enodeUrl)
const response = await fetch(rpcUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
method: 'admin_addPeer',
params: [PeerId.toString(peerId)],
id: 1
})
})
const { result } = await response.json()
return result
}
// Remove peer via admin_removePeer
async function removePeer(rpcUrl: string, enodeUrl: string): Promise<boolean> {
const peerId = PeerId.from(enodeUrl)
const response = await fetch(rpcUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
method: 'admin_removePeer',
params: [PeerId.toString(peerId)],
id: 1
})
})
const { result } = await response.json()
return result
}