This is the content of my rpc.js
plugin file:
const { createBitcoinRpc } = require('@carnesen/bitcoin-rpc')
const protocol = 'http'
const rpcuser = 'root'
const rpcpassword = 'toor'
const host = '127.0.0.1'
const port = '43782'
const rpcHref = `${protocol}://${rpcuser}:${rpcpassword}@${host}:${port}/`
const bitcoinRpc = createBitcoinRpc(rpcHref)
export default ({ app }, inject) => {
inject('bitcoinRpc', (method) =>
bitcoinRpc(method).then((result) => console.log('That was easy!', result))
)
}
This is the content of my nuxt.config.js
file:
...
plugins: [{ src: '@/plugins/gun.js' }, { src: '@/plugins/rpc.js' }],
...
If I call the method
this.$bitcoinRpc('getnewaddress')
within a component's methods, it results in an error. However, if I call this method inside the rpc
plugin itself, everything functions properly:
// plugins/rpc.js:
// Declare constants and inject above
...
bitcoinRpc('getnewaddress').then((result) =>
console.log('That was easy!', result)
)
The expected output is displayed in the terminal:
That was easy! 2N8LyZKaZn5womvLKZG2b5wGfXw8URSMptq 14:11:21
What could be causing the issue?