输入字段

策略决策中所有可用数据的完整参考

每个策略决策都可以通过 input 对象访问请求数据。本页面记录了您可以在策略中使用的所有可用字段。

网络

这些字段标识正在调用的区块链网络和 RPC 方法,允许您创建特定于链的策略或限制某些操作。

input.chain

TypeExample Values
string"ethereum", "polygon", "arbitrum", "optimism", "base"

请求的区块链网络标识符。使用此字段限制对特定链的访问、为每个网络应用不同的策略或完全阻止某些链。

示例

# Only allow transactions on Polygon and Base
allowed_chains := {"polygon", "base"}
 
deny if {
    not input.chain in allowed_chains
}
 
# Apply stricter limits on Ethereum mainnet
deny if {
    input.chain == "ethereum"
    input.usd_value > 1000
}

input.rpc_method

TypeExample Values
string"eth_sendTransaction", "eth_call", "eth_getBalance"

请求中的 JSON-RPC 方法名称。使用此字段允许或阻止特定操作。例如,您可以允许读取操作(eth_calleth_getBalance)同时限制写入操作(eth_sendTransaction)。

请注意,某些方法在平台级别受到限制,无法通过策略启用。

示例

# Only allow read-only methods
allowed_methods := {
    "eth_call",
    "eth_getBalance",
    "eth_getTransactionCount",
    "eth_getCode",
    "eth_getLogs"
}
 
deny if {
    not input.rpc_method in allowed_methods
}
 
# Block signing methods
deny if {
    input.rpc_method in {"eth_sign", "personal_sign", "eth_signTypedData"}
}

请求来源

这些字段提供有关请求来源的位置信息,支持基于地理位置的访问控制和区域法规合规性。

input.source_ip

TypeExample Values
string"192.168.1.1", "2001:db8::1"

发出请求的客户端的 IP 地址。将其用于基于 IP 的允许列表/阻止列表或实现基于来源的速率限制。

IP 解析

默认情况下,256 Blocks 使用连接客户端的 IP 地址。如果您的请求通过自己的基础设施代理,您可以通过 X-Forwarded-For 标头传递原始客户端 IP - 256 Blocks 将使用该标头中的第一个 IP 地址。

这在以下情况下很有用:

  • 请求通过您的后端服务器代理
  • 您需要传递最终用户的真实 IP 地址
  • 在开发环境中使用不同的 IP 地址测试策略

示例

# Block specific IP addresses
blocked_ips := {"192.168.1.100", "10.0.0.50"}
 
deny if {
    input.source_ip in blocked_ips
}
 
# Only allow requests from known infrastructure
allowed_ips := {"203.0.113.10", "203.0.113.11"}
 
deny if {
    not input.source_ip in allowed_ips
}

input.source_country

TypeExample Values
string"US", "GB", "DE", "UNKNOWN", "PRIVATE", "LOCALHOST"

source_ip 派生的两字母 ISO 3166-1 alpha-2 国家代码。将其用于地理限制、法规合规性或特定区域的策略。

国家映射每天刷新。对于公共 IP 地址,准确率通常为 95% 以上。

特殊值

对于非公共 IP 地址,返回以下值而不是国家代码:

ValueDescription
"PRIVATE"私有 IP 范围(10.x.x.x、172.16-31.x.x、192.168.x.x)
"LOCALHOST"回环地址(127.x.x.x)
"LINK_LOCAL"链路本地地址(169.254.x.x)
"MULTICAST"多播地址(224.x.x.x - 239.x.x.x)
"RESERVED"保留地址(240.x.x.x+)
"UNKNOWN"查找失败或不支持的地址类型

示例

# Block sanctioned countries
blocked_countries := {"KP", "IR", "CU", "SY", "RU"}
 
deny if {
    input.source_country in blocked_countries
}
 
# Only allow requests from specific regions
allowed_countries := {"US", "CA", "GB", "DE", "FR"}
 
deny if {
    not input.source_country in allowed_countries
    input.source_country != "PRIVATE"  # Allow internal/development traffic
}

交易参数

这些字段从 JSON-RPC 请求参数中提取。所有地址都规范化为小写并带有 0x 前缀,以便进行一致的比较。

input.from_address

TypeExample Value
string (nullable)"0x742d35cc6634c0532925a3b844bc9e7595f..."

发送者的钱包地址。这标识了发起交易或签名请求的人。使用此字段为特定钱包实现允许列表/阻止列表,或根据发送者应用不同的策略规则。

按 RPC 方法的来源

MethodParameter Location
eth_sendTransactionparams[0].from
eth_callparams[0].from
eth_signparams[0]
personal_signparams[1]
eth_signTypedDataparams[0]

示例

# Only allow transactions from approved wallets
allowed_senders := {
    "0x742d35cc6634c0532925a3b844bc9e7595f...",
    "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606..."
}
 
deny if {
    not input.from_address in allowed_senders
}

input.to_address

TypeExample Value
string (nullable)"0x742d35cc6634c0532925a3b844bc9e7595f..."

交易的接收者或目标地址。对于简单转账,这可能是钱包地址,或者对于合约交互,这是合约地址。在部署新合约时,该值为 null(合约创建交易没有接收者)。

按 RPC 方法的来源

MethodParameter Location
eth_sendTransactionparams[0].to
eth_callparams[0].to
eth_getBalanceparams[0]
eth_getTransactionCountparams[0]

示例

# Block transactions to known malicious addresses
blocked_addresses := {
    "0x000000000000000000000000000000000000dead",
    "0x1234567890abcdef..."
}
 
deny if {
    input.to_address in blocked_addresses
}

input.contract_addresses

TypeExample Value
array of strings["0x742d35cc...", "0xa0b86991..."]

请求中涉及的智能合约地址数组。这对于控制用户可以与哪些合约交互特别有用。对于可以查询多个合约的方法(如 eth_getLogs),数组可能包含多个地址。

按 RPC 方法的来源

MethodParameter LocationNotes
eth_sendTransactionparams[0].to仅当存在 datainput 字段时
eth_callparams[0].to调用合约时
eth_getCodeparams[0]目标合约地址
eth_getStorageAtparams[0]目标合约地址
eth_getLogsparams[0].address可以是单个地址或数组

示例

# Only allow interactions with approved contracts (e.g., USDT and USDC)
approved_contracts := {
    "0xdac17f958d2ee523a2206206994597c13d831ec7",
    "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"
}
 
deny if {
    some addr in input.contract_addresses
    not addr in approved_contracts
}

input.value_wei

TypeExample Value
string (nullable)"0xde0b6b3a7640000" (1 ETH in hex)

正在转移的原生代币价值,以十六进制字符串形式表示的 wei。Wei 是 ETH 的最小单位(1 ETH = 10^18 wei)。这是原始链上价值 - 对于基于 USD 的策略,请改用 input.usd_value

按 RPC 方法的来源

MethodParameter Location
eth_sendTransactionparams[0].value
eth_callparams[0].value

示例

# Block transactions transferring more than 10 ETH (in wei)
# 10 ETH = 10 * 10^18 wei = 0x8ac7230489e80000
deny if {
    input.value_wei != null
    to_number(input.value_wei) > 10000000000000000000
}
 
# Block zero-value transactions to specific contracts
deny if {
    input.value_wei == "0x0"
    some addr in input.contract_addresses
    addr == "0x..."
}

input.gas_limit

TypeExample Value
string (nullable)"0x5208" (21000 in hex)

允许交易消耗的最大燃料单位量,以十六进制字符串表示。简单的 ETH 转账使用 21,000 个燃料单位,而合约交互通常需要更多。

按 RPC 方法的来源

MethodParameter Location
eth_sendTransactionparams[0].gas
eth_callparams[0].gas

示例

# Block transactions with excessive gas limits (potential spam/abuse)
# 1,000,000 gas = 0xf4240
deny if {
    input.gas_limit != null
    to_number(input.gas_limit) > 1000000
}
 
# Don't sponsor high-gas transactions
denyGasSponsor if {
    input.gas_limit != null
    to_number(input.gas_limit) > 500000
}

input.gas_price

TypeExample Value
string (nullable)"0x3b9aca00" (1 gwei in hex)

传统(EIP-1559 之前)交易的燃料价格,以十六进制字符串形式表示的 wei。对于使用 max_fee_per_gas 的 EIP-1559 交易,此字段为 null

按 RPC 方法的来源

MethodParameter Location
eth_sendTransactionparams[0].gasPrice
eth_callparams[0].gasPrice

示例

# Block legacy transactions with extremely high gas prices
# 500 gwei = 500 * 10^9 = 0x746a528800
deny if {
    input.gas_price != null
    to_number(input.gas_price) > 500000000000
}
 
# Don't sponsor legacy transactions (prefer EIP-1559)
denyGasSponsor if {
    input.gas_price != null
    input.max_fee_per_gas == null
}

input.max_fee_per_gas

TypeExample Value
string (nullable)"0x77359400" (2 gwei in hex)

EIP-1559 交易的每个燃料单位的最大总费用,以十六进制字符串表示。这是发送者愿意支付的绝对最大值(基础费用 + 优先费用)。仅适用于 EIP-1559 交易类型。

按 RPC 方法的来源

MethodParameter Location
eth_sendTransactionparams[0].maxFeePerGas

示例

# Block transactions willing to pay excessive gas fees
# 1000 gwei = 1000 * 10^9 = 0xe8d4a51000
deny if {
    input.max_fee_per_gas != null
    to_number(input.max_fee_per_gas) > 1000000000000
}
 
# Only sponsor transactions with reasonable max fees
# 50 gwei = 50 * 10^9 = 0xba43b7400
denyGasSponsor if {
    input.max_fee_per_gas != null
    to_number(input.max_fee_per_gas) > 50000000000
}

input.max_priority_fee_per_gas

TypeExample Value
string (nullable)"0x3b9aca00" (1 gwei in hex)

EIP-1559 交易的每个燃料单位的最大优先费用(小费),以十六进制字符串表示。这是作为激励支付给区块生产者的部分。仅适用于 EIP-1559 交易类型。

按 RPC 方法的来源

MethodParameter Location
eth_sendTransactionparams[0].maxPriorityFeePerGas

示例

# Block transactions with excessive priority fees (potential MEV manipulation)
# 10 gwei = 10 * 10^9 = 0x2540be400
deny if {
    input.max_priority_fee_per_gas != null
    to_number(input.max_priority_fee_per_gas) > 10000000000
}
 
# Require reasonable priority fees for sponsored transactions
# 2 gwei = 2 * 10^9 = 0x77359400
denyGasSponsor if {
    input.max_priority_fee_per_gas != null
    to_number(input.max_priority_fee_per_gas) > 2000000000
}

丰富数据

这些字段由 256 Blocks 计算,以提供超出原始请求的额外上下文。

input.usd_value

TypeExample Value
number (nullable)1500.50

交易原生代币价值(value_wei)的 USD 等值,使用当前市场价格计算。这是实现支出限制和赞助控制最常用的字段。

价格每分钟从可靠的价格源(如 Chainlink)获取一次。如果交易没有价值(例如,纯合约调用),则该值可能为 null

示例

# Block transactions over $10,000
deny if {
    input.usd_value > 10000
}
 
# Don't sponsor transactions over $100
denyGasSponsor if {
    input.usd_value > 100
}
 
# Handle null values safely
deny if {
    input.usd_value != null
    input.usd_value > 50000
}

原始数据

对于上述结构化字段无法提供所需内容的高级用例。

input.raw_params

TypeExample Value
array[{"from": "0x...", "to": "0x...", "value": "0x...", "data": "0x..."}]

来自原始请求的完整、未修改的 JSON-RPC params 数组。当您需要访问通过结构化输入属性未公开的字段时使用此字段,例如:

  • 用于函数签名检测的合约调用数据(data 字段)
  • EIP-2930 交易的访问列表
  • 自定义或非标准字段

示例

# Block ERC-20 transfer function calls
# Function signature: transfer(address,uint256) = 0xa9059cbb
deny if {
    params := input.raw_params[0]
    params.data != null
    startswith(params.data, "0xa9059cbb")
}
 
# Block ERC-20 approve function (0x095ea7b3)
deny if {
    params := input.raw_params[0]
    params.data != null
    startswith(params.data, "0x095ea7b3")
}
输入字段 | 256 Blocks