Skip to content

Instantly share code, notes, and snippets.

@svetlanama
Last active April 30, 2019 13:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save svetlanama/fa09d31df68ab0c4d5fe942954b8f818 to your computer and use it in GitHub Desktop.
Save svetlanama/fa09d31df68ab0c4d5fe942954b8f818 to your computer and use it in GitHub Desktop.
Gas relay (tests example)
var tabookey = require('tabookey-gasless');
// step0
const gasPricePercent = 20
relay_client_config = {
txfee: 12,
force_gasPrice: 2000000000, //override requested gas price
force_gasLimit: 4000029, //override requested gas limit.
verbose: process.env.DEBUG
}
var provider = new tabookey.RelayProvider(web3.currentProvider, {});
// step1
// Note the contract should be deployed
TokenContract.web3.setProvider(relayProvider)
// step2
try {
let initRelayHubRes = await tokenContract.initRelayHub(hubAddress);
console.log("initRelayHubRes:", initRelayHubRes);
} catch (error) {
}
// IMPORTANT:
// need to make deposit once after deploying the contract
try {
let deposit = web3.utils.toWei("0.1", "ether")
let res = await tokenSwapContract.deposit({value: deposit});
//console.log("deposit res:", res);
} catch (error) {
}
it("test transfer gas free", async function() {
web3.setProvider(provider);
let initBalance = await web3.eth.getBalance(account_one)
let tokenTestAddress = "0x8......."
let tokenTestRelay = await new web3.eth.Contract(Token._json.abi, tokenTestAddress);
let result = await tokenTestRelay.methods.transfer(account_two, 100).send({ from: account_one, gasPrice: 2000000000, gasLimit: 65000});
});
// TokenContract.sol should have deposit function in case you not use external script
function deposit() public payable {
get_relay_hub().depositFor.value(msg.value)(address(this));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment