config
Reactive configuration for Flow JS SDK and FCL
Status
- Status Last Updated: June 16th 2021
- Stable: Yes
- Risk of Breaking Change: Low
Overview
Usage
import {config} from "@onflow/sdk"
config().subscribe(configData => console.log("CONFIG", configData))
config().put("foo", "bar")
config()
.put("foo", "bar")
.put("baz", "rawr")
var configValue = await config().get("woot")
console.log(configValue)
var configValue = await config().get("woot", "fallback")
console.log(configValue)
config.put("woot", "woot")
var configValue = await config().get("woot", "fallback")
console.log(configValue)
config().put("count", 1)
var count = await config().get("count", 0)
console.log(count)
config().update("count", oldValue => oldValue + 1)
var count = await config().get("count", 0)
console.log(count)
config().delete("woot")
var configValue = await config().get("woot", "fallback")
console.log(configValue)
config()
.put("scope.A", 1)
.put("scope.B", 1)
var scopeValues = await config().where(/^scope\.\s+/)
console.log(scopeValues)
Configurations
Known configuration values in FCL
Access Node
accessNode.api
(default: emulator url) -- Where FCL will used to communicate with the Flow blockchain.accessNode.key
(default: null) -- Some Access Nodes require an api key.
import {config} from "@onflow/fcl"
if (process.env.NODE_ENV === "production") {
config()
.put("accessNode.api", process.env.ACCESS_NODE_API)
.put("accessNode.key", process.env.ACCESS_NODE_KEY)
}
Decode
See fcl.decode
for more details on decode.
decoder.*
-- Custom decoders for parsing JSON-CDC
import {config, query} from "@onflow/fcl"
function Woot({x, y}) {
this.x = x
this.y = y
}
config()
.put("decoder.Woot", woot => new Woot(woot))
var data = await fcl.query({
cadence: `
pub struct Woot {
pub var x: Int
pub var y: Int
init(x: Int, y: Int) {
self.x = x
self.y = y
}
}
pub fun main(): [Woot] {
return [Woot(x: 1, y: 2), Woot(x: 3, y: 4), Woot(x: 5, y: 6)]
}
`
})
console.log(data)
Wallets
See fcl.currentUser
for more details on authentication.
wallet.discovery
(default: FCL wallet discovery service url) -- Where FCL will attempt to authenticate
import {config} from "@onflow/fcl"
if (process.env.NODE_ENV === "development") {
config()
.put("discovery.wallet", "http://localhost:8701/flow/authenticate")
}