# User Signing

This is a relatively advanced use case. If you use the signed typed data JSONRPC endpoint, Fortmatic will support this as well.

## Signing Methods

{% tabs %}
{% tab title="Web3 Pre-1.0 Personal Sign" %}
![](/files/-Lsso-8QtItJ9nG91gPO)

```javascript
// Initialize provider
import Fortmatic from 'fortmatic';
import Web3 from 'web3';

// Required to convert message to Hex
const ethUtil = require('ethereumjs-util');

const fm = new Fortmatic('YOUR_API_KEY');
window.web3 = new Web3(fm.getProvider());

web3.eth.getAccounts((error, accounts) => {
 
  if (error) throw error;
 
  const from = accounts[0];
  const msg = ethUtil.bufferToHex(new Buffer('YOUR_MESSAGE', 'utf8'));
  const params = [msg, from];
  const method = 'personal_sign';
 
  web3.currentProvider.sendAsync({
    id: 1,
    method,
    params,
    from,
  }, function(error, result) {
    if (error) throw error;
    console.log(result);
  });

});
```

{% endtab %}

{% tab title="Web3 1.0-Beta Personal Sign" %}
![](/files/-Lsso-8QtItJ9nG91gPO)

```javascript
// Initialize provider
import Fortmatic from 'fortmatic';
import Web3 from 'web3';

const fm = new Fortmatic('YOUR_API_KEY');
window.web3 = new Web3(fm.getProvider());

// Personal Sign
const text = 'YOUR_MESSAGE';

const accounts = await web3.eth.getAccounts();
const from = accounts[0];

const result = await web3.eth.personal.sign(text, from);
```

{% endtab %}

{% tab title="Sign Typed Data v1" %}
![](/files/-Lsso2s52aYtMyXnG-OJ)

```javascript
// Initialize provider
import Fortmatic from 'fortmatic';
import Web3 from 'web3';

const fm = new Fortmatic('YOUR_API_KEY');
window.web3 = new Web3(fm.getProvider());

web3.eth.getAccounts(function(error, accounts) {
 
  if (error) throw error;
 
  const from = accounts[0];
  const msg = [
    {
      type: 'string',
      name: 'fullName',
      value: 'John Doe'
    },
    {
      type: 'uint32',
      name: 'userId',
      value: '1234'
    }
  ];
  const params = [msg, from];
  const method = 'eth_signTypedData';
 
  web3.currentProvider.sendAsync({
    id: 1,
    method,
    params,
    from,
  }, function(error, result) {
    if (error) throw error;
    console.log(result);
  });

});
```

{% hint style="warning" %}
On **Web3 1.0 Beta 55**? For all signing methods, replace this...

```
web3.currentProvider.sendAsync({
  id: 1,
  method,
  params,
  from,
}, function(error, result) {
  if (error) throw error;
  console.log(result);
});
```

...with this

```
web3.currentProvider.sendPayload({
  id: 1,
  method,
  params,
  from,
}).then(console.log);
```

{% endhint %}
{% endtab %}

{% tab title="Sign Typed Data v3" %}
This is based on [EIP 712](https://eips.ethereum.org/EIPS/eip-712).

![](/files/-Lsso5KkPVcJjGZ-_ANG)

```javascript
// Initialize provider
import Fortmatic from 'fortmatic';
import Web3 from 'web3';

const fm = new Fortmatic('YOUR_API_KEY');
window.web3 = new Web3(fm.getProvider());

web3.eth.getAccounts(function(error, accounts) {
 
  if (error) throw error;
 
  const from = accounts[0];
  const payload = {
    "types": {
      "EIP712Domain": [
        {
          "name":"name",
          "type":"string"
        },
        {
          "name":"version",
          "type":"string"
        },
        {
          "name":"verifyingContract",
          "type":"address"
        }
      ],
      "Greeting": [
        {
          "name":"contents",
          "type":"string"
        }
      ]
    },
    "primaryType":"Greeting",
    "domain":{
      "name":"Fortmatic",
      "version":"1",
      "verifyingContract":"0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"
    },
    "message":{
      "contents":"Hello, from Fortmatic!"
    }
  }
        
  const params = [from, payload];
  const method = 'eth_signTypedData_v3';
 
  web3.currentProvider.sendAsync({
    id: 1,
    method,
    params,
    from,
  }, function(error, result) {
    if (error) throw error;
    console.log(result);
  });
 
});
```

{% hint style="warning" %}
On **Web3 1.0 Beta 55**? For all signing methods, replace this...

```
web3.currentProvider.sendAsync({
  id: 1,
  method,
  params,
  from,
}, function(error, result) {
  if (error) throw error;
  console.log(result);
});
```

...with this

```
web3.currentProvider.sendPayload({
  id: 1,
  method,
  params,
  from,
}).then(console.log);
```

{% endhint %}
{% endtab %}

{% tab title="Sign Typed Data v4" %}
This is based on [EIP 712](https://eips.ethereum.org/EIPS/eip-712).

![](/files/-Lsso5KkPVcJjGZ-_ANG)

```javascript
// Initialize provider
import Fortmatic from 'fortmatic';
import Web3 from 'web3';

const fm = new Fortmatic('YOUR_API_KEY');
window.web3 = new Web3(fm.getProvider());

web3.eth.getAccounts(function(error, accounts) {
 
  if (error) throw error;
 
  const from = accounts[0];
  const payload = {
    "types": {
      "EIP712Domain": [
        {
          "name":"name",
          "type":"string"
        },
        {
          "name":"version",
          "type":"string"
        },
        {
          "name":"verifyingContract",
          "type":"address"
        }
      ],
      "Greeting": [
        {
          "name":"contents",
          "type":"string"
        }
      ]
    },
    "primaryType":"Greeting",
    "domain":{
      "name":"Fortmatic",
      "version":"1",
      "verifyingContract":"0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"
    },
    "message":{
      "contents":"Hello, from Fortmatic!"
    }
  }
        
  const params = [from, payload];
  const method = 'eth_signTypedData_v4';
 
  web3.currentProvider.sendAsync({
    id: 1,
    method,
    params,
    from,
  }, function(error, result) {
    if (error) throw error;
    console.log(result);
  });
 
});
```

{% hint style="warning" %}
On **Web3 1.0 Beta 55**? For all signing methods, replace this...

```
web3.currentProvider.sendAsync({
  id: 1,
  method,
  params,
  from,
}, function(error, result) {
  if (error) throw error;
  console.log(result);
});
```

...with this

```
web3.currentProvider.sendPayload({
  id: 1,
  method,
  params,
  from,
}).then(console.log);
```

{% endhint %}
{% endtab %}
{% endtabs %}


---

# 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.fortmatic.com/web3-integration/user-signing.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.
