# eth_signTransaction - Chiliz RPC Method

Signs a transaction with the private key of the specified account on Chiliz without submitting it to the network.

> **Why Chiliz?** Build on the sports-first blockchain powering 2M+ fan token wallets and dozens of licensed sports partnerships with licensed partnerships with major football clubs, MiCA-compliant in EU, OG Esports integration, and SportFi DeFi infrastructure.

> **Security Warning:** Public Dwellir endpoints do not keep unlocked signers. On shared infrastructure, `eth_signTransaction` commonly returns a deprecation, unsupported-method, or account-management error instead of a signed payload. For production use, **sign transactions client-side** using libraries like [ethers.js](https://docs.ethers.org/) or [web3.py](https://github.com/ethereum/web3.py), then broadcast with [`eth_sendRawTransaction`](https://www.dwellir.com/docs/chiliz/eth_sendRawTransaction).

## When to Use This Method

`eth_signTransaction` is relevant for sports organizations, entertainment brands, and fan engagement platform developers in limited scenarios:

- **Understanding the Signing Flow** - Learn how transaction signing works before implementing client-side signing
- **Local Development** - Sign transactions on a local dev node (Hardhat, Anvil, Ganache) where accounts are unlocked
- **Offline Signing Workflows** - Generate signed transaction payloads for later broadcast

## Best Practices

- Sign transactions client-side using wallet libraries for production applications
- Never expose private keys to node endpoints; use `eth_sendRawTransaction` with pre-signed transactions
- Use `eth_signTransaction` only in test environments or for air-gapped signing validation

## Request Parameters

- `from` (`DATA (20 bytes), required`): Address of the account to sign with (must be unlocked)
- `to` (`DATA (20 bytes), optional`): Recipient address (omit for contract creation)
- `gas` (`QUANTITY, optional`): Gas limit for the transaction (default: 90000)
- `gasPrice` (`QUANTITY, optional`): Gas price in wei (legacy transactions)
- `value` (`QUANTITY, optional`): Value to send in wei
- `data` (`DATA, optional`): Compiled contract code or encoded method call
- `nonce` (`QUANTITY, optional`): Transaction nonce (defaults to eth_getTransactionCount)

## Request Example

```json
{
  "jsonrpc": "2.0",
  "method": "eth_signTransaction",
  "params": [
    {
      "from": "0x407d73d8a49eeb85d32cf465507dd71d507100c1",
      "to": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
      "gas": "0x76c0",
      "gasPrice": "0x9184e72a000",
      "value": "0x9184e72a",
      "data": "0x",
      "nonce": "0x0"
    }
  ],
  "id": 1
}
```

## Response Fields

- `raw` (`DATA, required`): The RLP-encoded signed transaction, ready for eth_sendRawTransaction
- `tx` (`Object, required`): The transaction object including v, r, s signature fields

## Successful Response

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "raw": "0xf86c808609184e72a0008276c094a94f5374fce5edbc8e2a8697c15331677e6ebf0b849184e72a801ba0fe38ca4e44a30002ac54af7cf922a6ac2ba11b7571d7c13e32e8ce2c6c8a...",
    "tx": {
      "nonce": "0x0",
      "gasPrice": "0x9184e72a000",
      "gas": "0x76c0",
      "to": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
      "value": "0x9184e72a",
      "input": "0x",
      "v": "0x1b",
      "r": "0xfe38ca4e44a30002ac54af7cf922a6ac2ba11b7571d7c13e32e8ce2c6c8a...",
      "s": "0x3d850e0b25e3c7a3e4da3a7c1b1a4e3b5c6d7e8f9a0b1c2d3e4f5a6b7c8d9e..."
    }
  }
}
```

## Code Examples

cURL
JavaScript
Python
Go

```bash
# Local dev node only. Public Dwellir endpoints do not expose unlocked-account signing.
curl -X POST http://127.0.0.1:8545 \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "method": "eth_signTransaction",
    "params": [{
      "from": "0x407d73d8a49eeb85d32cf465507dd71d507100c1",
      "to": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
      "gas": "0x76c0",
      "gasPrice": "0x9184e72a000",
      "value": "0x9184e72a",
      "nonce": "0x0"
    }],
    "id": 1
  }'
```

```javascript
// Recommended: client-side signing with ethers.js
import { Wallet, JsonRpcProvider, parseEther } from 'ethers';

const provider = new JsonRpcProvider('https://api-chiliz-mainnet-archive.n.dwellir.com/YOUR_API_KEY');
const wallet = new Wallet('YOUR_PRIVATE_KEY', provider);

const tx = {
  to: '0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b',
  value: parseEther('0.1'),
  gasLimit: 21000
};

// Sign without sending
const signedTx = await wallet.signTransaction(tx);
console.log('Signed Chiliz tx:', signedTx);

// Send later with eth_sendRawTransaction
const receipt = await provider.broadcastTransaction(signedTx);
console.log('Tx hash:', receipt.hash);
```

```python
from web3 import Web3
from eth_account import Account

w3 = Web3(Web3.HTTPProvider('https://api-chiliz-mainnet-archive.n.dwellir.com/YOUR_API_KEY'))

# Recommended: client-side signing
account = Account.from_key('YOUR_PRIVATE_KEY')

tx = {
    'to': '0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b',
    'value': w3.to_wei(0.1, 'ether'),
    'gas': 21000,
    'gasPrice': w3.eth.gas_price,
    'nonce': w3.eth.get_transaction_count(account.address),
    'chainId': w3.eth.chain_id
}

signed = account.sign_transaction(tx)
print(f'Signed Chiliz tx: {signed.raw_transaction.hex()}')

# Send later
tx_hash = w3.eth.send_raw_transaction(signed.raw_transaction)
print(f'Tx hash: {tx_hash.hex()}')
```

```go
package main

import (
    "context"
    "crypto/ecdsa"
    "fmt"
    "log"
    "math/big"

    "github.com/ethereum/go-ethereum/common"
    "github.com/ethereum/go-ethereum/core/types"
    "github.com/ethereum/go-ethereum/crypto"
    "github.com/ethereum/go-ethereum/ethclient"
)

func main() {
    client, err := ethclient.Dial("https://api-chiliz-mainnet-archive.n.dwellir.com/YOUR_API_KEY")
    if err != nil {
        log.Fatal(err)
    }

    // Recommended: client-side signing
    privateKey, err := crypto.HexToECDSA("YOUR_PRIVATE_KEY_HEX")
    if err != nil {
        log.Fatal(err)
    }

    publicKey := privateKey.Public().(*ecdsa.PublicKey)
    fromAddress := crypto.PubkeyToAddress(*publicKey)

    nonce, err := client.PendingNonceAt(context.Background(), fromAddress)
    if err != nil {
        log.Fatal(err)
    }

    toAddress := common.HexToAddress("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b")
    tx := types.NewTransaction(nonce, toAddress, big.NewInt(100000000), 21000, big.NewInt(10000000000), nil)

    chainID, err := client.ChainID(context.Background())
    if err != nil {
        log.Fatal(err)
    }

    signedTx, err := types.SignTx(tx, types.NewEIP155Signer(chainID), privateKey)
    if err != nil {
        log.Fatal(err)
    }

    fmt.Printf("Signed Chiliz tx hash: %s\n", signedTx.Hash().Hex())
}
```

## Common Use Cases

### 1. Offline Transaction Signing

Sign transactions on an air-gapped machine for later broadcast:

```javascript
import { Wallet } from 'ethers';

async function createSignedTransaction(privateKey, to, value, { chainId, nonce, gasLimit }) {
  const wallet = new Wallet(privateKey);
  const tx = {
    to,
    value,
    gasLimit,
    nonce,
    chainId,
  };

  const signedTx = await wallet.signTransaction(tx);
  // Store signedTx and broadcast from an online machine
  return signedTx;
}
```

### 2. Batch Transaction Preparation

Pre-sign multiple transactions for sequential submission on Chiliz:

```javascript
async function prepareBatch(wallet, transactions) {
  const signed = [];

  for (let i = 0; i < transactions.length; i++) {
    const tx = {
      ...transactions[i],
      nonce: baseNonce + i
    };
    signed.push(await wallet.signTransaction(tx));
  }

  return signed; // Submit via eth_sendRawTransaction in order
}
```

## Related Methods

- [`eth_sendRawTransaction`](https://www.dwellir.com/docs/chiliz/eth_sendRawTransaction) - Broadcast a signed transaction
- [`eth_sendTransaction`](https://www.dwellir.com/docs/chiliz/eth_sendTransaction) - Sign and send in one step (requires unlocked account)
- [`eth_accounts`](https://www.dwellir.com/docs/chiliz/eth_accounts) - List accounts available for signing
