Skip to content

Tenzorum/tenzorum

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tenzorum

Tenzorum

Easy to use SDK for implementing gasless transactions

npm Version License Downloads Build Status

Dependencies

Users must have an environment capable of running web3@1.0.0

Package Version Docs Description
web3 npm The core of web3

Tenzorum TSNN SDK

Utility for signing transactions and interaction with TSNN.

Installation

npm i tenzorum --save

About

To onboard a user to be able to use gasless transactions the user's app must have 2 components.

  1. Access to a private key (ideally from a secure enclave)
const privateKey = "d51729c3b597d162d7be8f83c8ee4eb137db72e7e0828d7709a1a5b274afe017";
  1. Deployed a Personal Multisignature Wallet for the user
import {deployPersonalMultisig} from tenzSdk;
const personalMultisigWallet = await deployPersonalMultisig(<publicKey from privateKey>)

returns 0xf8894138aa4d7b54b7d49afa9d5600cdb5178721

👩‍🚀 User

For better UX it's recommended to deploy a ens username which resolves to the user's personal multisig wallet. This can be done all at once using the deployUserAccount method.

import {deployUserAccount} from 'tenzorum';
deployUserAccount('user.ens-name.eth', "0xf8894138aa4d7b54b7d49afa9d5600cdb5178721");

You can then initialise the SDK

const tenzSdk = require('tenzorum');
tenzSdk.initSdk(web3, privateKey, personalWalletAddress);
/*ES6*/
import {initSdk, transferTokensWithTokenReward} from 'tenzorum';
initSdk(web3, privateKey, personalWalletAddress);

⛽️ Gasless Transactions

The user's wallet can then access transferring tokens via gasless transactions easily with the following function calls.

const result = await tenzSdk.transferTokensWithTokenReward(tokenAddress, tenTokens, toAddress, oneToken);
console.log(result);

This will print out a message in the following format as expected in the body of POST request by TSNN:

{
  "v":"0x1b",
  "r":"0x2a061c04485a307802d76f3e4c7fda40ec4d3390df3c6df28fd6c3165ca1fb59",
  "s":"0x5dd8b1d92512baa9ce7e49cad004a45c4bdabf8b852c99f522740f62b955a6c6",
  "from":"0x9E48c4A74D618a567CD657579B728774f35B82C5",
  "to":"0xf74694642a81a226771981cd38df9105a133c111",
  "value":"0",
  "data":"0x947aca55000000000000000000000000f938bfdc53f72cb7a4b1946969ba0cce05c902c6",
  "rewardType":"0x0000000000000000000000000000000000000000",
  "rewardAmount":"0"
}

where:

  • v, r, s - components of the signature of the message
  • from - source address that signed the message
  • to - target address if sending ether, or token contract address for token transfer
  • value - amount of ether to send
  • data - function payload like token transfer data or any other function call
  • rewardType - address(0) for ether, and token contract address for tokens payable as fee
  • rewardAmount - how much of ether/token should be paid as the fee

For full working example check example.js.

About

NPM utility module for signing transactions and interacting with TSNN

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published