# 免gas兑换

### 接口**调用图**

![](https://3392740180-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LSTh_zo_IUKEGh-Qy-n-3765750170%2Fuploads%2FP5HfVfcnyN9lEmvsYEif%2Fimage.png?alt=media\&token=a02029f8-cd50-4fc7-a186-afb292309b00)

### 时序图

![](https://3392740180-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LSTh_zo_IUKEGh-Qy-n-3765750170%2Fuploads%2FTt3LFSp8aykEYLNpqULO%2Fimage.png?alt=media\&token=db227721-e0f6-473c-bb66-9bca50d809b0)

### 说明

1. **调用 "**[**获取币种汇率接口**](https://docs.cn.omnibridge.pro/integration/get-base-info)**", 获取返回值isSupportNoGas, 为 Y 表示支持免 gas 兑换**
2. **调用 "**[**创建订单接口**](https://docs.cn.omnibridge.pro/integration/create-order)**", 并传递isSupportNoGas字段, 成功后会返回noGasTxInfo 字段, 为待签名的 call\_data**
3. **对 call\_data 进行签名,获取r,s,v,rawTransaction等签名后的数据**
4. **调用 "**[**上传免gas兑换订单接口**](https://docs.cn.omnibridge.pro/integration/free-gas-swap)**", 传递r,s,v,rawTransaction和 "**[**创建订单接口**](https://docs.cn.omnibridge.pro/integration/create-order)**"返回的 orderId即可**

**步骤 3 示例代码**

```javascript
 const privateKey = ''; // private key
 const transactionData = '{
  gasLimit: 100000,
  data: '0xaxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
  chainId: 56,
  to: '0x0000000000000xxxxx',
  nonce: 50,
  gasPrice: '3150000000'
}'
 const account = web3.eth.accounts.privateKeyToAccount(privateKey);
 const signedTx = await account.signTransaction(transactionData);
 const r = signedTx.r;
 const s = signedTx.s;
 const v = signedTx.v;
 const rawTransaction = signedTx.rawTransaction;
```

**1. 接口调用：**\
https\://{host}/gt/swap/v1/noGasSwap

**2. 请求参数示例**

| 参数             | 是否必须 | 说明                                      |
| -------------- | ---- | --------------------------------------- |
| orderId        | 是    | eg：5d3b383f-5b58-4a35-87b6-2de8d23a492e |
| r              | 是    | eg：0xxxxxxx                             |
| s              | 是    | eg：0xxxxxxx                             |
| v              | 是    | eg: 0xxx                                |
| rawTransaction | 是    | eg: 0xxxxxxx                            |

**3.请求参数示例**

```

{
    //订单号
    "orderId": "5d3b383f-xxxx-xxxx-xxxx-2de8d23a492e",
    "r": "0xxxx",
    "s": "0xxxxx",
    "v": "0xxx",
    "rawTransaction": "0xxxxxxxxx"
}

```

**4.返回结果示例**

```
{
    "orderId": "5d3b383f-xxxx-xxxx-xxxx-2de8d23a492e",
    "transactionHash": "0xxxxxxxxxxxxxx"
}
```

**5.返回参数说明**

| 字段名称    | 字段              | 数据类型   | 备注      |
| ------- | --------------- | ------ | ------- |
| 订单号     | orderId         | String | 订单号     |
| 交易 hash | transactionHash | String | 交易 hash |

### **代码示例**

**java代码示例**

````
```java
OkHttpClient client = new OkHttpClient().newBuilder()
  .build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\n    \"orderId\": \"5d3b383f-xxx-xxx-87b6-xxx\",\n    \"r\": \"0xxxx\",\n    \"s\": \"0xxxx\",\n    \"v\": \"0xxxx\",\n    \"rawTransaction\": \"0xxxx\"\n}");
Request request = new Request.Builder()
  .url("{host}/gt/swap/v1/noGasSwap")
  .method("POST", body)
  .addHeader("Content-Type", "application/json")
  .build();
Response response = client.newCall(request).execute();
```
````

&#x20;**curl示例**

````
```powershell
curl --location '{host}/gt/swap/v1/noGasSwap' \
--header 'Content-Type: application/json' \
--data '{
    "orderId": "5d3b383f-xxx-xxx-87b6-xxx",
    "r": "0xxxx",
    "s": "0xxxx",
    "v": "0xxxx",
    "rawTransaction": "0xxxx"
}'
```
````

#### Postman示例

<figure><img src="https://3392740180-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LSTh_zo_IUKEGh-Qy-n-3765750170%2Fuploads%2FbG4RYgUvE5BNAMdDfhxE%2Fimage.png?alt=media&#x26;token=d3b638d0-fab1-4cb9-93c9-b48eeb3bd542" alt=""><figcaption></figcaption></figure>

###
