Skip to main content

Sign a message

string message = "Hello, Dynamic!";
string signature = await DynamicSDK.Instance.Networks.Evm.SignMessage(
    wallet.Id, message);

Debug.Log($"Signature: {signature}");

Sign typed data (EIP-712)

Sign structured data according to the EIP-712 standard:
using Newtonsoft.Json;
using System.Collections.Generic;

var typedData = JsonConvert.DeserializeObject<Dictionary<string, object>>(@"{
    ""types"": {
        ""EIP712Domain"": [
            {""name"": ""name"", ""type"": ""string""},
            {""name"": ""version"", ""type"": ""string""},
            {""name"": ""chainId"", ""type"": ""uint256""}
        ],
        ""Mail"": [
            {""name"": ""from"", ""type"": ""string""},
            {""name"": ""to"", ""type"": ""string""},
            {""name"": ""contents"", ""type"": ""string""}
        ]
    },
    ""primaryType"": ""Mail"",
    ""domain"": { 
        ""name"": ""Example"", 
        ""version"": ""1"", 
        ""chainId"": 1 
    },
    ""message"": { 
        ""from"": ""Alice"", 
        ""to"": ""Bob"", 
        ""contents"": ""Hello!"" 
    }
}");

string signature = await DynamicSDK.Instance.Networks.Evm.SignTypedData(
    wallet.Id, typedData);

Complete example

using DynamicSDK.Core;
using Newtonsoft.Json;
using UnityEngine;
using System.Collections.Generic;
using System.Linq;

public class EvmSigningManager : MonoBehaviour
{
    private BaseWallet _evmWallet;
    
    private void Start()
    {
        _evmWallet = DynamicSDK.Instance.Wallets.UserWallets
            .FirstOrDefault(w => w.Chain.ToUpper() == "EVM");
    }
    
    public async void SignSimpleMessage()
    {
        if (_evmWallet == null)
        {
            Debug.LogError("No EVM wallet available");
            return;
        }
        
        string message = "Sign this message to verify your identity";
        
        try
        {
            string signature = await DynamicSDK.Instance.Networks.Evm.SignMessage(
                _evmWallet.Id, message);
            
            Debug.Log($"Message signed successfully");
            Debug.Log($"Signature: {signature}");
        }
        catch (System.Exception ex)
        {
            Debug.LogError($"Signing failed: {ex.Message}");
        }
    }
    
    public async void SignTypedData()
    {
        if (_evmWallet == null)
        {
            Debug.LogError("No EVM wallet available");
            return;
        }
        
        var typedData = new Dictionary<string, object>
        {
            { "types", new Dictionary<string, object>
                {
                    { "EIP712Domain", new List<object>
                        {
                            new Dictionary<string, string> { { "name", "name" }, { "type", "string" } },
                            new Dictionary<string, string> { { "name", "version" }, { "type", "string" } },
                            new Dictionary<string, string> { { "name", "chainId" }, { "type", "uint256" } }
                        }
                    },
                    { "Permit", new List<object>
                        {
                            new Dictionary<string, string> { { "name", "owner" }, { "type", "address" } },
                            new Dictionary<string, string> { { "name", "spender" }, { "type", "address" } },
                            new Dictionary<string, string> { { "name", "value" }, { "type", "uint256" } },
                            new Dictionary<string, string> { { "name", "nonce" }, { "type", "uint256" } },
                            new Dictionary<string, string> { { "name", "deadline" }, { "type", "uint256" } }
                        }
                    }
                }
            },
            { "primaryType", "Permit" },
            { "domain", new Dictionary<string, object>
                {
                    { "name", "MyToken" },
                    { "version", "1" },
                    { "chainId", 1 }
                }
            },
            { "message", new Dictionary<string, object>
                {
                    { "owner", _evmWallet.Address },
                    { "spender", "0xRecipientAddress" },
                    { "value", "1000000000000000000" },
                    { "nonce", 0 },
                    { "deadline", DateTimeOffset.UtcNow.AddHours(1).ToUnixTimeSeconds() }
                }
            }
        };
        
        try
        {
            string signature = await DynamicSDK.Instance.Networks.Evm.SignTypedData(
                _evmWallet.Id, typedData);
            
            Debug.Log($"Typed data signed successfully");
            Debug.Log($"Signature: {signature}");
        }
        catch (System.Exception ex)
        {
            Debug.LogError($"Signing failed: {ex.Message}");
        }
    }
}

Next steps