# Solana Chain Signatures Contract

The Solana Chain Signatures Contract provides an implementation of the abstract `ChainSignatureContract` for Solana-based blockchains using Anchor and Solana's Web3.js. It enables interaction with Chain Signatures programs deployed on Solana.

## Usage

```ts twoslash
import { contracts, constants } from 'signet.js'
import { AnchorProvider, Wallet } from '@coral-xyz/anchor'
import { Connection, PublicKey, Keypair } from '@solana/web3.js'

const connection = new Connection('https://api.devnet.solana.com')
const wallet = new Wallet(/* Use your actual keypair here */ Keypair.generate())
const provider = new AnchorProvider(
  connection,
  wallet,
  AnchorProvider.defaultOptions()
)

const contract = new contracts.solana.ChainSignatureContract({
  provider,
  programId: new PublicKey(constants.CONTRACT_ADDRESSES.SOLANA.TESTNET_DEV),
})
```

### With Custom Configuration

```ts twoslash
import { contracts, constants } from 'signet.js'
import { AnchorProvider, Wallet, type Idl } from '@coral-xyz/anchor'
import { Connection, PublicKey, Keypair } from '@solana/web3.js'

// Your custom IDL, e.g. loaded from ./custom-idl.json
declare const customIdl: contracts.solana.ChainSignaturesProject & Idl

const connection = new Connection('https://api.devnet.solana.com')
const wallet = new Wallet(Keypair.generate())
const provider = new AnchorProvider(
  connection,
  wallet,
  AnchorProvider.defaultOptions()
)

const contract = new contracts.solana.ChainSignatureContract({
  provider,
  programId: new PublicKey(constants.CONTRACT_ADDRESSES.SOLANA.TESTNET_DEV),
  config: {
    rootPublicKey: 'secp256k1:...',
    requesterAddress: 'Dewq9xyD1MZi1rE588XZFvK7uUqkcHLgCnDsn9Ns4H9M',
    idl: customIdl,
  },
})
```

## Parameters

| Parameter                              | Type                           | Description                                                                                                                 |
| -------------------------------------- | ------------------------------ | --------------------------------------------------------------------------------------------------------------------------- |
| `args`                                 | `object`                       | Configuration options for the contract                                                                                      |
| `args.provider`                        | `AnchorProvider`               | Anchor provider instance for interacting with Solana                                                                        |
| `args.programId`                       | `string \| PublicKey`          | The program ID of the deployed ChainSignatures program                                                                      |
| `args.config?`                         | `object`                       | Optional configuration object                                                                                               |
| `args.config.rootPublicKey?`           | `RootPublicKey`                | Optional root public key; derived from program ID if not provided                                                           |
| `args.config.requesterAddress?`        | `string`                       | Optional requester wallet address. If not provided, defaults to the wallet address. Fee payer is always the wallet address. |
| `args.config.disableRetryOnRateLimit?` | `boolean`                      | If true, disables @solana/web3.js automatic retry on 429 responses.                                                         |
| `args.config.idl?`                     | `ChainSignaturesProject & Idl` | Optional custom IDL. If not provided, the default ChainSignatures IDL will be used                                          |

## Working Examples

* [Integration tests](https://github.com/sig-net/signet.js/blob/main/tests/integration/solana/Solana.integration.test.ts) — contract setup and signing on devnet
