Best Practices

1. Context Management

Always use context for timeout and cancellation:

goctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()

market, err := client.GetMarket(ctx, marketID)

2. Private Key Management

Never hardcode private keys:

go// ❌ Bad
privateKey := "0x1234567890..."

// ✅ Good
privateKey := os.Getenv("PRIVATE_KEY")

// ✅ Even better: Use a secrets management service
// privateKey, err := getFromVault("gp_private_key")

3. Connection Pooling

Reuse client connections:

4. Error Handling

Implement proper error handling and logging:

5. Gas Optimization

Batch multiple operations when possible:

6. Testing

Use the provided test utilities:


Troubleshooting

Issue: Connection Refused

Symptom: connection refused error when creating client

Solution:

  1. Verify RPC endpoint is correct and accessible

  2. Check internet connectivity

  3. Test endpoint directly: curl https://your-rpc-endpoint.com

Issue: Insufficient Balance

Symptom: Transaction fails with "insufficient funds"

Solution:

  1. Check wallet balance: client.GetBalance(ctx, userAddress)

  2. Fund wallet with native tokens for gas fees

  3. Account for gas costs in your budget

Issue: Order Expired

Symptom: Orders are immediately rejected as expired

Solution:

  1. Ensure server time is synchronized

  2. Increase order expiry window

  3. Check market resolution time hasn't passed

Issue: Rate Limiting

Symptom: Frequent 429 errors

Solution:

  1. Implement exponential backoff retry

  2. Spread requests over time

  3. Consider using batch endpoints

Issue: Transaction Pending

Symptom: Transactions not confirming

Solution:

  1. Check transaction hash on blockchain explorer

  2. Verify network isn't congested

  3. Increase gas price if needed

  4. Wait for network finality

Last updated