signaling_contract_sdk 1.0.2 copy "signaling_contract_sdk: ^1.0.2" to clipboard
signaling_contract_sdk: ^1.0.2 copied to clipboard

Type-safe Dart SDK for blockchain signaling smart contracts with auto-generated bindings, Ethereum/EVM support, and comprehensive deployment utilities.

Signaling Contract SDK #

Pub License Dart

A type-safe Dart SDK for interacting with blockchain signaling smart contracts. This package provides auto-generated bindings for the Signaling contract, built on top of web3dart for seamless Ethereum/EVM compatibility.

Features #

  • πŸ” Type-safe contract bindings - Auto-generated from Solidity ABIs
  • πŸš€ Easy-to-use API - Intuitive methods for contract interaction
  • πŸ“¦ EVM Compatible - Works with Ethereum, Polygon, Arbitrum, and other EVM chains
  • πŸ”„ Auto-generated - Bindings generated from TypeChain artifacts
  • βœ… Full deployment support - Deploy and initialize contracts programmatically
  • πŸ“– Well-documented - Comprehensive examples and API documentation
  • πŸ§ͺ Thoroughly tested - 39+ test cases with full coverage

Installation #

Add this to your pubspec.yaml:

dependencies:
  signaling_contract_sdk: ^1.0.0

Then run:

dart pub get

Quick Start #

import 'package:signaling_contract_sdk/signaling_contract_sdk.dart';
import 'dart:typed_data';

void main() async {
  // Create credentials
  final credentials = EthPrivateKey.fromHex('0x...');

  // Connect to existing contract
  final signaling = await SignalingContract.connect(
    rpcUrl: 'https://eth.public.blastapi.io',
    contractAddress: EthereumAddress.fromHex('0x...'),
    credentials: credentials,
  );

  // Set an offer (for WebRTC signaling)
  final offer = 'v=0\r\no=- ...'.codeUnits;
  final txHash = await signaling.setOffer(Uint8List.fromList(offer));
  print('Offer set! Tx: $txHash');

  // Retrieve an offer
  final storedOffer = await signaling.getOffer(credentials.address);
  print('Retrieved offer: $storedOffer');
}

Contract Functions #

Main Functions #

setOffer(bytes offer)

Store an offer for WebRTC signaling. Only callable by the offerer.

final offer = 'sdp_offer_data'.codeUnits;
await signaling.setOffer(Uint8List.fromList(offer));

getOffer(address offerer)

Retrieve a stored offer from any user.

final offer = await signaling.getOffer(offererAddress);
print('Offer data: ${offer.signal}');
print('Created at: ${offer.creationTime}');

setAnswer(bytes answer, address offerer)

Set an answer in response to an offer.

final answer = 'sdp_answer_data'.codeUnits;
await signaling.setAnswer(Uint8List.fromList(answer), offererAddress);

getAnswer(address answerer, address offerer)

Retrieve a stored answer.

final answer = await signaling.getAnswer(answererAddress, offererAddress);

initialize(address owner)

Initialize the contract and set the owner (called after deployment).

await signaling.initialize(credentials.address);

Admin Functions #

  • transferOwnership(address newOwner) - Transfer contract ownership
  • upgradeToAndCall(address newImplementation, bytes data) - Upgrade contract (UUPS)

Deployment #

import 'package:signaling_contract_sdk/signaling_contract_sdk.dart';
import 'package:http/http.dart' as http;

Future<void> main() async {
  final credentials = EthPrivateKey.fromHex('0x...');
  
  // Deploy
  final contract = await SignalingContract.deploy(
    rpcUrl: 'http://localhost:8545',
    credentials: credentials,
  );
  
  print('Deployed to: ${contract.contract.address.eip55With0x}');
  
  // Initialize
  await contract.initialize(credentials.address);
  
  // Verify owner
  final owner = await contract.owner();
  print('Owner: ${owner.eip55With0x}');
}

For production deployments with UUPS proxy support, use Hardhat from the TypeScript package:

cd packages/typescript/signaling-contract
npx hardhat run scripts/deploy.ts --network mainnet

Events #

The contract emits two events:

// Emitted when an offer is set
event proposeOffer(
  address indexed offerer,
  Signal offer
);

// Emitted when an answer is set  
event proposeAnswer(
  address indexed offerer,
  address indexed answerer,
  Signal answer
);

Listen to events:

final filter = FilterOptions.events(
  contract: DeployedContract(...),
  event: contractAbi.events.first,
);

client.events(filter).listen((event) {
  print('Event: $event');
});

Supported Networks #

This SDK works with any EVM-compatible blockchain:

  • βœ… Ethereum (mainnet, Sepolia, Goerli)
  • βœ… Polygon (mainnet, Mumbai)
  • βœ… Arbitrum (mainnet, Sepolia)
  • βœ… Optimism (mainnet, Sepolia)
  • βœ… Base (mainnet)
  • βœ… BSC (mainnet, testnet)
  • βœ… Ganache (local development)

Just change the rpcUrl parameter to your target network's RPC endpoint.

Development & Testing #

Setup #

# Install dependencies
dart pub get

# Run analysis
dart analyze

# Run all tests
dart test

Testing with Ganache (Local) #

# Start Ganache
docker-compose up -d evm

# Run integration tests
dart test test/ganache_integration_test.dart

Test Coverage #

  • 24 static validation tests (ABI & bytecode)
  • 4 RPC connectivity tests
  • 10 deployment & interaction tests
  • 1 event test

All tests passing βœ…

API Documentation #

Full API documentation is available on pub.flutter-io.cn.

Examples #

See the example directory for complete working examples, including:

  • Basic contract interaction
  • Deployment and initialization
  • Event listening
  • Error handling

License #

This project is licensed under the LGPL-3.0 License - see LICENSE file for details.

Contributing #

Contributions are welcome! Please open an issue or PR on GitHub.

Support #

For issues, questions, or suggestions:

0
likes
145
points
130
downloads

Publisher

unverified uploader

Weekly Downloads

Type-safe Dart SDK for blockchain signaling smart contracts with auto-generated bindings, Ethereum/EVM support, and comprehensive deployment utilities.

Repository (GitHub)
View/report issues

Topics

#blockchain #ethereum #smart-contracts #web3 #evm

Documentation

API reference

License

unknown (license)

Dependencies

convert, http, wallet, web3dart

More

Packages that depend on signaling_contract_sdk