diff --git a/website/pages/en/developing/assemblyscript-api.mdx b/website/pages/en/developing/assemblyscript-api.mdx index 7ed222075936..bbe395130da7 100644 --- a/website/pages/en/developing/assemblyscript-api.mdx +++ b/website/pages/en/developing/assemblyscript-api.mdx @@ -808,6 +808,61 @@ The base `Entity` class and the child `DataSourceContext` class have helpers to - `getBoolean(key: string): boolean` - `getBigDecimal(key: string): BigDecimal` +### DataSourceContext in Manifest + +The `context` section within `dataSources` allows you to define key-value pairs that are accessible within your subgraph mappings. The available types are `Bool`, `String`, `Int`, `Int8`, `BigDecimal`, `Bytes`, `List`, and `BigInt`. + +Here is a YAML example illustrating the usage of various types in the `context` section: + +```yaml +dataSources: + - kind: ethereum/contract + name: ContractName + network: mainnet + context: + bool_example: + type: Bool + data: true + string_example: + type: String + data: 'hello' + int_example: + type: Int + data: 42 + int8_example: + type: Int8 + data: 127 + big_decimal_example: + type: BigDecimal + data: '10.99' + bytes_example: + type: Bytes + data: '0x68656c6c6f' + list_example: + type: List + data: + - type: Int + data: 1 + - type: Int + data: 2 + - type: Int + data: 3 + big_int_example: + type: BigInt + data: '1000000000000000000000000' +``` + +- `Bool`: Specifies a Boolean value (`true` or `false`). +- `String`: Specifies a String value. +- `Int`: Specifies a 32-bit integer. +- `Int8`: Specifies an 8-bit integer. +- `BigDecimal`: Specifies a decimal number. Must be quoted. +- `Bytes`: Specifies a hexadecimal string. +- `List`: Specifies a list of items. Each item needs to specify its type and data. +- `BigInt`: Specifies a large integer value. Must be quoted due to its large size. + +This context is then accessible in your subgraph mapping files, enabling more dynamic and configurable subgraphs. + ### Common AssemblyScript Issues There are certain [AssemblyScript](https://github.com/AssemblyScript/assemblyscript) issues that are common to run into during subgraph development. They range in debug difficulty, however, being aware of them may help. The following is a non-exhaustive list of these issues: diff --git a/website/pages/en/developing/creating-a-subgraph.mdx b/website/pages/en/developing/creating-a-subgraph.mdx index 1bae3145b2fd..bdbebefba35b 100644 --- a/website/pages/en/developing/creating-a-subgraph.mdx +++ b/website/pages/en/developing/creating-a-subgraph.mdx @@ -109,6 +109,13 @@ dataSources: address: '0x2E645469f354BB4F5c8a05B3b30A929361cf77eC' abi: Gravity startBlock: 6175244 + context: + foo: + type: Bool + data: true + bar: + type: String + data: 'bar' mapping: kind: ethereum/events apiVersion: 0.0.6 @@ -146,6 +153,8 @@ The important entries to update for the manifest are: - `dataSources.source.startBlock`: the optional number of the block that the data source starts indexing from. In most cases, we suggest using the block in which the contract was created. +- `dataSources.context`: key-value pairs that can be used within subgraph mappings. Supports various data types like `Bool`, `String`, `Int`, `Int8`, `BigDecimal`, `Bytes`, `List`, and `BigInt`. Each variable needs to specify its `type` and `data`. These context variables are then accessible in the mapping files, offering more configurable options for subgraph development. + - `dataSources.mapping.entities`: the entities that the data source writes to the store. The schema for each entity is defined in the schema.graphql file. - `dataSources.mapping.abis`: one or more named ABI files for the source contract as well as any other smart contracts that you interact with from within the mappings.