PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, September 25, 2022

[FIXED] How to modify PaymentSplitter.sol to autopay?

 September 25, 2022     blockchain, openzeppelin, remix, solidity     No comments   

Issue

I've done little tests with the paymentSplitter code from OpenZeppelin and I don't seem to find a proper way to make it pay automatically. Gotta say that I'm a rookie at this and probably theres a stupid thing I'm missing

The PaymentSplitter contract uses the function release() so the wallets can pay the gas fee and claim their payment, but this is not worth for me as I want the received Ether to go to liquidity on 2 other coins-- And call a function right after

So my doubts may be pretty dumb but, is there a way to use the contract balance for gas fee? Then, create an event that executes the release function when a deposit is made?

Since I've read lots of documentation and I'm still nowhere near, I'd love some simple examples!

EDIT:

Today I found this video: https://www.youtube.com/watch?v=IVq3gR2L5Iw

This should work properly right? Is there any tip on setting the right gas price for 3 transactions?


Solution

is there a way to use the contract balance for gas fee?

No. The gas fee is always paid by the transaction sender. You need a private key to the sender address to be able to send a transaction. And the contract address private key is unknown.


You can create an off-chain app (in JS, Python, etc.), that will send a transaction to the PaymentSplitter in predefined situations (cron, reaction to some other event, ...). Example using web3js:

const Web3 = require("web3");
const web3 = new Web3(providerUrl);
web3.eth.accounts.wallet.add(senderPrivateKey);
const contract = new web3.eth.Contract(abiJson, contractAddress);

const executeRelease = async () => {
    await contract.methods.release(contractFunctionParams).send({
        from: senderAddress
    });
}

// invoke when needed
executeRelease();

Or you can make use of already existing implementations such as Chainlink Cron Jobs that will execute the transaction for you (for a payment made in LINK, token of the Chainlink service).



Answered By - Petr Hejda
Answer Checked By - Cary Denson (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing