Transactions
Your users are executing Ethereum transactions while paying for them with Credit/Debit card. In order to preserve the intrinsic properties of the blockchain, the transactions need to be executed by your users, meaning that the Ethereum transactions must be signed by your users private keys.

Signing Transactions

Signing of the transactions can be done in various ways

LimePay Wallet

You can sign the transactions through the LimePay Wallet of the user by performing:
1
payment.signWithLimePayWallet(password) // returns new Promise<>
Copied!
Where payment is an instance of a payment crated by LimePay.load and password is the password used when Creating the LimePay Wallet.
NOTE: Only Shopper that uses LimePay Wallets can sign the transactions this way.

External Wallet

Sign with Encrypted keystore file

1
payment.signWithEncryptedWallet(jsonKeyStore, password) // Returns new Promise<>
Copied!

Sing with private key

1
payment.signWithPrivateKey(privateKey) // Returns new Promise<>
Copied!

Sign with decrypted Ethers.js based wallet

1
payment.signWithDecryptedWallet(decryptedWallet) // Returns new Promise<>
Copied!

Sign with mnemonic

1
payment.signWithMnemonic(mnemonic, nonEnglishLocaleWorldList?) // Returns new Promise<>
Copied!

Hardware Wallet

In order to sign the transactions in the payment with hardware wallet, one would need to do the following:
1
const transactions = payment.getSignableTransactions() // Returns array of signable transactions
2
const signedTransactions = await myFunctionThatSigns(transactions) // sign the transactions using the hardware wallet
3
4
// Set the signed transactions in the payment
5
payment.setSignedTransactions(signedTransactions);
Copied!
Where payment is an instance of a payment crated by LimePay.load

Transaction

Every transaction in the transactions array is object with the following properties:
Attribute
Type
Description
Required
to
string
Address that the transaction will be sent to
Yes
abi
string
The ABI of the contract that is deployed at the to address
Yes
gasPrice
string
Gas price of the transaction
Yes
gasLimit
integer
Gas limit of the transactions
Yes
value
integer
Amount of wei that is going to be sent along with the transaction. Default is 0
No
functionName
string
Name of the function that will be called
Yes
functionParams
array
Array of parameters that are going to be passed to the function
No

Example (DEPRECATED since 0.3.6)

Since version [email protected] the web library performs the signing of the transactions in the background so there is no need to do the following operation if you are using the 0.3.7 version of the library. Since version 0.3.7 you no longer have to provide and sign the transactions using the Limepay.Transactions interface. The signing is performed through the instance of the payment
The example below demonstrates how you can build and sign the transactions.
  1. 1.
    ERC20 Approve transaction that will approve the dApp contract to spend (charge) ERC20 Tokens on the behalf of the user.
  2. 2.
    Transaction that will "buy some service" from the dApp contract. Internally buySomeService executes transferFrom ERC20 call and charges the dApp user with tokens for the service.
1
const transactions = [{
2
to:'0xc8b06aA70161810e00bFd283eDc68B1df1082301', //ERC20 Contract address
3
abi: ERC20ABI,
4
gasLimit: 4700000,
5
value: 0,
6
functionName: "approve",
7
functionParams: ["0x07F3fB05d8b7aF49450ee675A26A01592F922734", 10000000000000000000] // tokens in 18 decimals format
8
},
9
{
10
to: '0x07F3fB05d8b7aF49450ee675A26A01592F922734', // Address of the dApp contract
11
abi: dAppContractABI,
12
gasLimit: 4700000,
13
value: 0,
14
functionName: "buySomeService",
15
functionParams: ["0x1835f2716ba8f3ede4180c88286b27f070efe985"] // Parameter provided to the `buySomeService` function
16
}
17
];
18
19
Limepay.Transactions.signWithPrivateKey(transactions, privateKey) // returns Promise <>
Copied!
NOTE: The provided transactions must be in the right order as they will be executed sequentially. In the case above, the first will be the approve transaction and then it will be the buySomeService transaction.
Note: The transactions signed by the user MUST match the provided transactions when you have created the payment through the LimePay SDK. If they does not match, the payment will result in failure (the user will not be charged nor funded).

Related Resources

Last modified 2yr ago