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 afterwards.

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

Use our signature helper to construct the signature which will need to be passed to the widget.


You'll need to import the signature helper:

import { signSmartContractData } from '@wert-io/widget-sc-signer';

And create a configuration object:

const signedData = signSmartContractData(options, privateKey);

The signedData object is the object you will pass back to the widget along with the widget options.


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 commodity_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. Precision of 8 decimal places, please round up or you will get 9004 signature error code.0.03 (must be less than 8 decimal places)
sc_addressStringThe address of the smart contract.0x00000000000000000000000000000
00000000002
sc_input_dataStringInput data that will be used for the smart contract execution, in hex format.

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

For CCD see example below.
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`

/* We advise you not to use the private key on the frontend
It is used here for example only
*/
const privateKey = '0x687079c151720e44c97b40c00ac257699fa4fc2c96ef617d964113c059dafe3d';
const signedData = signSmartContractData({
address: '0x96D5990185022212d367A0e09263B12Dbb4EE06A',
commodity: 'ETH',
network: 'ethereum',
commodity_amount: 0.3,
sc_address: '0xC545CEae428785a5AE77bfF262600deC7F7d76d2',
sc_input_data: '0x9dae76ea000000000000000000000000000000000000000000000000000000000000003700000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001',
}, privateKey);

Signed data generation example for Concordium smart contract operation

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`

/* We advise you not to use the private key on the frontend
It is used here for example only
*/
const privateKey = '0x687079c151720e44c97b40c00ac257699fa4fc2c96ef617d964113c059dafe3d';
const signedData = signSmartContractData({
address: '44XC2R7gPwTtXc4197hQjgXSkayWxHtUmj7PsRLz3cD8UJ5mzP',
commodity: 'CCD',
network: 'concordium',
commodity_amount: 700,
sc_address: '7b22696e646578223a20313734322c2022737562696e646578223a20307d',
sc_input_data: '7b22656e747279706f696e74223a227472616465722e627579222c22706172616d73223a22307836313035303030303030303030303030227d',
}, privateKey);

sc_input_data example for Concordium smart contract operations

As sc_input_data you should send data that will be added to the transaction to your contract and that will be used to call on your contract.
It should be sent as a hex and contain an entry point, method and parameters to be called on a contract.

Example:

7b22656e747279706f696e74223a227472616465722e627579222c22706172616d73223a22307836313035303030303030303030303030227d

Which, when decoded, would look like this:

 {"entrypoint":"trader.buy","params":"0x6105000000000000"}

Where the entry point is the contract name and the method is divided by a dot. That format is the only available way to call the contract method based on their protocol.

Params are hex-encoded bytes - binary representation of the contract’s method arguments. You should create it yourself using your own libraries/sdks.


Documentation related to this page