Templates
Template 1: Checking Condition
package main
import (
"fmt"
"time"
)
// ConditionResult represents the result of condition evaluation
type ConditionResult struct {
Satisfied bool
Timestamp time.Time
Response float64
}
// condition evaluates user-defined conditions and returns the result
func condition() ConditionResult {
// Return the condition result
return ConditionResult{
Satisfied: true,
Timestamp: time.Now(),
Response: 0,
}
}
func main() {
// Call the condition function
result := condition()
// Print the results
fmt.Println("Condition satisfied:", result.Satisfied)
fmt.Println("Timestamp:", result.Timestamp.Format(time.RFC3339))
fmt.Println("Response:", result.Response)
if result.Response != 0 {
fmt.Println("Response:", result.Response)
}
}
Template 2: Fetching Dynamic Arguments
package main
import (
"encoding/json"
"fmt"
)
func main() {
// Create result object with parameter name matching the function parameter name
resultPayload := map[string]interface{}{
"<function_parameter_name>": <value to be passed>, // Use the exact parameter name from the smart contract
}
jsonValue, _ := json.Marshal(resultPayload)
fmt.Println("Payload received:", string(jsonValue))
}
Last updated