# Bulk Insert

This feature is used when two or more addContractLog or createContractLog must be contained in a single transaction during the contract life cycle or when more than one contracts are sent as a bulk transaction.

## Contents

<table><thead><tr><th width="346">Name</th><th>Description</th></tr></thead><tbody><tr><td><a href="#1.-getunsignedtxaddcontractlog">1. getUnsignedTxAddContractLog</a></td><td>This feature receives the addContractLog transaction creation message.</td></tr><tr><td><a href="#2.-getunsignedtxcreatecontractfile">2. getUnsignedTxCreateContractFile</a></td><td>This feature receives the addContractFile transaction creation message.</td></tr><tr><td><a href="#3.-getgasestimationsignandbroadcast">3. getGasEstimationSignAndBroadcast</a></td><td>This feature estimates the gas fee required for lining up transaction messages.</td></tr><tr><td><a href="#4.-signandbroadcast">4. signAndBroadcast</a></td><td>This feature executes multiple transactions at once.</td></tr><tr><td><a href="#5.-parameter-description">5. Parameter Description</a></td><td>Parameters required to call API.</td></tr></tbody></table>

### 1. getUnsignedTxAddContractLog

This function generates addContractLog transactions as messages. Events that happen in a contract life cycle are contained in the addContractLog. Once the gas fee for generating a message is calculated, the transaction is created by the function that executes messages.\
\&#xNAN;*\* For a more detailed guide on calculating the gas fee and executing messages, please refer to functions 3 and 4.*

#### Parameters

<table><thead><tr><th width="160.33333333333331">Name</th><th width="244">Type</th><th>Example</th></tr></thead><tbody><tr><td>wallet</td><td><mark style="color:blue;">Object</mark> (<mark style="color:green;">FirmaWalletService</mark>)</td><td>You can check how to use your wallet in the "<a href="https://github.com/FirmaChain/firma-js#create-wallet-account">firma-js of the Github repository</a>".</td></tr><tr><td>contractHash</td><td><mark style="color:blue;">String</mark></td><td>"da39330a6dfd90a91563603950f742240fa222580beecf36e141fe6410184e8b1669119707"</td></tr><tr><td>timeStamp</td><td><mark style="color:blue;">Number</mark></td><td>1669182016039</td></tr><tr><td>eventName</td><td><mark style="color:blue;">String</mark></td><td>"createContract"</td></tr><tr><td>ownerAddress</td><td><mark style="color:blue;">String</mark></td><td>"firma1nssuz67am2uwc2hjgvphg0fmj3k9l6cx65ux9u"</td></tr><tr><td>jsonString</td><td><mark style="color:blue;">String</mark> (<mark style="color:green;">JSON</mark>)</td><td>"{Encryption:{type:"JWT",alg:"HS256"},contracts:[{target:"contractor1",email:"contractor1@gmail.com"}]}"</td></tr></tbody></table>

#### Return value

```json5
{
  typeUrl: '/firmachain.firmachain.contract.MsgAddContractLog',
  value: {
    creator: 'firma1nssuz67am2uwc2hjgvphg0fmj3k9l6cx65ux9u',
    contractHash: 'da39330a6dfd90a91563603950f742240fa222580beecf36e141fe6410184e8b',
    timeStamp: 1669199517,
    eventName: 'createContract',
    ownerAddress: 'firma1nssuz67am2uwc2hjgvphg0fmj3k9l6cx65ux9u',
    jsonString: '"{}"'
  }
}
```

### 2. getUnsignedTxCreateContractFile

This function generates "createContractLog" transactions as messages. Events that happen in a contract life cycle are contained in the addContractLog. Once the gas fee for generating a message is calculated, the transaction is created by the function that executes messages.\
\&#xNAN;*\* For a more detailed guide on calculating the gas fee and executing messages, please refer to functions 3 and 4.*

**Parameters**

<table><thead><tr><th width="209.33333333333331">Name</th><th width="244">Type</th><th>Example</th></tr></thead><tbody><tr><td>wallet</td><td><mark style="color:blue;">Object</mark> (<mark style="color:green;">FirmaWalletService</mark>)</td><td>You can check how to use your wallet in the "<a href="https://github.com/FirmaChain/firma-js#create-wallet-account">firma-js of the Github repository</a>".</td></tr><tr><td>fileHash</td><td><mark style="color:blue;">String</mark></td><td>"da39330a6dfd90a91563603950f742240fa222580beecf36e141fe6410184e8b1669119707"</td></tr><tr><td>timeStamp</td><td><mark style="color:blue;">Number</mark></td><td>1669182016039</td></tr><tr><td>ownerList</td><td><mark style="color:blue;">Array</mark> (<mark style="color:blue;">String</mark>)</td><td>["firma1epg9kx7nqz32dykj23p6jreqfh5x0wdy5a43qc"]</td></tr><tr><td>metaDataJsonString</td><td><mark style="color:blue;">String</mark> (<mark style="color:green;">JSON</mark>)</td><td>'{"storage":"ipfs","encryptIpfsHash":["U2FsdGVkX19UsL3m7Cq2bOtTCQArqZTuLgz7mfdRtXM2MnIgm67GM26GtPELsVL8s4+IN2Vj9FbFzpFj3rwfaw=="]}'</td></tr><tr><td>txMisc (Not required)</td><td><mark style="color:blue;">Object</mark> (<mark style="color:green;">TxMisc</mark>)</td><td>{fee:200000,gas:163821,memo:"custom message"}</td></tr></tbody></table>

#### Return value

```json5
{
  typeUrl: '/firmachain.firmachain.contract.MsgCreateContractFile',
  value: {
    creator: 'firma1nssuz67am2uwc2hjgvphg0fmj3k9l6cx65ux9u',
    fileHash: 'da39330a6dfd90a91563603950f742240fa222580beecf36e141fe6410184e8b1669199724',
    timeStamp: 1669199724,
    ownerList: [
      'firma1nssuz67am2uwc2hjgvphg0fmj3k9l6cx65ux9u',
      'firma1nssuz67am2uwc2hjgvphg0fmj3k9l6cx65ux9u'
    ],
    metaDataJsonString: '"{}"'
  }
}
```

### 3. getGasEstimationSignAndBroadcast

This function estimates the gas fee required when generating transactions of the message list created by functions 1 and 2. When using Bulk Insert, there is a high chance where the gas fee could exceed the default gas fee(0.02fct). Therefore, prior to the execution of the transaction, the gas fee must be estimated properly.

#### Parameters

<table><thead><tr><th width="172.33333333333331">Name</th><th width="256">Type</th><th>Example</th></tr></thead><tbody><tr><td>wallet</td><td><mark style="color:blue;">Object</mark> (<mark style="color:green;">FirmaWalletService</mark>)</td><td><em>You can check the usage through the "</em><a href="https://firmachain-1.gitbook.io/firmachain/module-comming-soon/contract/log#undefined"><em>Github example source</em></a><em>".</em></td></tr><tr><td>msgList</td><td><mark style="color:blue;">msgList</mark> (<mark style="color:green;">EncodeObject[]</mark>)</td><td><strong>1</strong> or <strong>2</strong> "Return value" Array value.</td></tr></tbody></table>

#### Return value

```json5
239964
```

#### Example Run Image

<figure><img src="/files/35bmaLSvsfhMp9CMzYsE" alt=""><figcaption></figcaption></figure>

### 4. signAndBroadcast

This function lists the messages generated from functions 1 and 2 and then generates the message list as transactions.

#### Parameters

<table><thead><tr><th width="209.33333333333331">Name</th><th width="248">Type</th><th>Example</th></tr></thead><tbody><tr><td>wallet</td><td><mark style="color:blue;">Object</mark> (<mark style="color:green;">FirmaWalletService</mark>)</td><td>You can check how to use your wallet in the "<a href="https://github.com/FirmaChain/firma-js#create-wallet-account">firma-js of the Github repository</a>".</td></tr><tr><td>msgList</td><td><mark style="color:blue;">msgList</mark> (<mark style="color:green;">EncodeObject[]</mark>)</td><td><strong>1</strong> or <strong>2</strong> "Return value" Array value.</td></tr><tr><td>txMisc (Not required)</td><td><mark style="color:blue;">Object</mark> (<mark style="color:green;">TxMisc</mark>)</td><td>{fee:200000,gas:163821,memo:"custom message"}</td></tr></tbody></table>

#### Return value

```json5
{
  code: 0,
  height: 428306,
  rawLog: '[
  {
    "events": [{
      "type":"message",
      "attributes":[{"key":"action","value":"CreateContractFile"}]
    }]
  }, {
    "msg_index":1,
    "events":[{
      "type":"message",
      "attributes": [{"key":"action","value":"CreateContractFile"}]
    }]
  }, {
    "msg_index":2,
    "events":[{
      "type":"message",
      "attributes": [{"key":"action","value":"CreateContractFile"}]
    }]
  }]',
  transactionHash: 'DC03E4872A97325D3AAA58B9B6296476E32AD42D8A448F6C7460F9D260CCBB56',
  gasUsed: 98872,
  gasWanted: 113703
}
```

#### Image of the transaction verified in Blockchain Explorer

<figure><img src="/files/ItCTMRFziaM1efhkQLrp" alt=""><figcaption></figcaption></figure>

### 5. Parameter Description

<table><thead><tr><th width="238">Name</th><th>Description</th></tr></thead><tbody><tr><td>wallet</td><td>Unique wallet parameter created from the user’s Mnemonic.<br>This parameter can be called by using the Wallet.fromMnemonic function from the FirmaSDK module.</td></tr><tr><td><p>contractHash &#x26;</p><p>fileHash</p></td><td>This parameter contains the mapped information of a file or a text to a predesignated length. This information can be used to track Contract on the network and allows developers to add multiple Logs to a single Contract Hash. Using the FirmaUtil, developers can call the hash value of a file or a text and we recommend developers to use the unique value.</td></tr><tr><td>timeStamp</td><td>This parameter timestamps a certain event, action or a result. This parameter is displayed as the "Unix time stamp" format and must be written in numbers.</td></tr><tr><td>eventName</td><td>This parameter contains information related to a certain event, action or a result. For instance, looking at the life cycle of a contract, this parameter can be devided into “Contract Creation”, “Invite Signatories”, “Sign”, “All Signatues Received” and “Contract Complete”.</td></tr><tr><td>ownerAddress</td><td>For this parameter, please enter your FirmaChain wallet address. The owner of the wallet can be anyone. (e.g. “Service Wallet Address” or “Signatory’s Wallet Address”).</td></tr><tr><td>ownerList</td><td>This parameter contains the wallet address list of the users related to a contract. This parameter can be added for the same purpose as the ownerAddress parameter.</td></tr><tr><td>jsonString &#x26;<br>metaDataJsonString</td><td>This parameter contains additional information related to a contract. Additional information for instance, includes, public key (encrypted), location of the saved contract, contract download link or the e-mail address of the owner of the contract. Please write this parameter as JSON text format.<br><em>* There are no set standard so please customize this parameter to suit the purpose of your project.</em></td></tr><tr><td>msgList</td><td>This parameter contains the list of messages that is used to execute transactions.<br>* List can contain different transaction messages.</td></tr><tr><td>txMisc</td><td><p>This object contains the gas fee that is deducted when a transaction is called upon.</p><p><em>* The default gas fee is set at 0.02fct.</em></p></td></tr></tbody></table>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.firmachain.org/master/developer/modules/contract/bulk-insert.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
