Generate signed data

Create the signed data object

⚠️

If your Ethereum or Polygon smart contract can't be verified on Etherscan/Polygonscan, please check verifying your smart contract and return here afterward.

Use our signature helper to construct the signature, which must be passed to the widget.

Once the signature helper is installed, you can use the following code snippet:

// Import the signature helper
import { signSmartContractData } from '@wert-io/widget-sc-signer';

// Create a configuration object with signed data
const signedData = signSmartContractData(options, privateKey);

// Pass the `signedData` object back to the widget along with the widget options
const wertWidget = new WertWidget({
    ...signedData,
    ...otherWidgetOptions,
});

The options you will need to pass to the object are:

PropertyTypeDescriptionExample
addressStringThe user’s address that receives the token/NFT will also act as a fallback address if a smart contract can’t be executed. In case of fallback, we will transfer thecommodity_amount to this address.0x00000000000000000000000000000
00000000001
commodityStringCryptocurrency which should be sent to the smart contract, see Supported coins and blockchainscommodity: 'ETH'
networkStringNetwork for the cryptocurrency, see Supported coins and blockchainsnetwork: 'ethereum'
commodity_amountNumberAmount of cryptocurrency necessary for executing the given smart contract.
The precision is 8 decimal places; please round up, or you will get a 9004 signature error code.
0.03 (must be no more than 8 decimal places)
sc_addressStringThe address of the smart contract.0x00000000000000000000000000000
00000000002
sc_input_dataStringInput data used for the smart contract execution in hex format.

For Tezos, this must be Michelson code passed as JSON transformed into hex format.

See Forming input data.
0x40c10f1900000000000000000000000
085f584812fc19c69e4dd586f06df93aa7
bdadd4d000000000000000000000000
000000000000000000000000016345
785d8a0000

Signed data generation example

import { signSmartContractData } from '@wert-io/widget-sc-signer';
import { v4 as uuidv4 } from 'uuid';
import { Buffer } from 'buffer/';

window.Buffer = Buffer; // needed to use `signSmartContractData` in browser

const signedData = signSmartContractData(
  {
    address: '0x96D5990185022212d367A0e09263B12Dbb4EE06A',
    commodity: 'ETH',
    network: 'ethereum',
    commodity_amount: 0.005,
    sc_address: '0x3b2305502bd6f8b1eb2ed474ac15c61c6702b18b',
    sc_input_data:
      '0x9dae76ea000000000000000000000000000000000000000000000000000000000000003700000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001',
  },
  privateKey
);

const wertWidget = new WertWidget({
	partner_id: 'YOUR_PARTNER_ID',
  ...signedData,
});

You can find further examples on GitHub.

If you cannot use our signature helper, follow the Signing a payment request guide to manually create the signature.


Private key

For the sandbox environment, Wert will provide you with the private key; if you don’t have it, please get in touch with us via email or Discord.

For production, you need to generate the key pair and provide the public key to Wert. Please refer to Keypair creation.

⚠️

To keep your private key safe, you should construct the signature on your backend and pass it to the frontend when initializing the widget.

Please note: This is NOT a wallet private key, it is just a digital signature to encrypt the request.