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 but performing:

Limepay.Transactions.signWithLimePayWallet(transactions, limePayToken, password)
.then(signedTransactions => {})
.catch(error => {})

Where limePayToken is the token returned when Creating Payment 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

Limepay.Transactions.signWithEncryptedWallet(transactions, jsonKeyStore, password)
.then(signedTransactions => {})
.catch(error => {})

Sing with private key

Limepay.Transactions.signWithPrivateKey(transactions, privateKey)
.then(signedTransactions => {})
.catch(error => {})

Sign with decrypted Ethers.js based wallet

Limepay.Transactions.signWithDecryptedWallet(transactions, decryptedWallet)
.then(signedTransactions => {})
.catch(error => {})

Sign with mnemonic

Limepay.Transactions.signWithMnemonic(transactions, mnemonic, nonEnglishLocaleWorldList?)
.then(signedTransactions => {})
.catch(error => {})

transactions is array of transaction objects that are covered in details below.

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

The example below demonstrates how you can build and sign the transactions.

  1. ERC20 Approve transaction that will approve the dApp contract to spend (charge) ERC20 Tokens on the behalf of the user.

  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.

const transactions = [{
to:'0xc8b06aA70161810e00bFd283eDc68B1df1082301', //ERC20 Contract address
abi: ERC20ABI,
gasLimit: 4700000,
value: 0,
functionName: "approve",
functionParams: ["0x07F3fB05d8b7aF49450ee675A26A01592F922734", 10000000000000000000] // tokens in 18 decimals format
},
{
to: '0x07F3fB05d8b7aF49450ee675A26A01592F922734', // Address of the dApp contract
abi: dAppContractABI,
gasLimit: 4700000,
value: 0,
functionName: "buySomeService",
functionParams: ["0x1835f2716ba8f3ede4180c88286b27f070efe985"] // Parameter provided to the `buySomeService` function
}
];
‚Äč
Limepay.Transactions.signWithPrivateKey(transactions, privateKey) // returns Promise <>

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