I reply to all queries on the forums and via email, once per day, Monday to Friday (not weekends).

If you are new here, please see some information on how to ask for support. Thank you!

Giving coins to users programmatically

dashed-slug.net Forums General discussion Giving coins to users programmatically

Viewing 15 posts - 1 through 15 (of 17 total)
  • Author
    Posts
  • #11490
    Anonymous
    Inactive

    Hello,

    I been working on a Gaming Service that will allow games to interface to my WordPress to check for user accounts and cloud saving/encryption but I want to add a feature to allow the Games to give players my site’s custom coins as a reward but the wp_wallets_txs database is kinda weird and has no reference/example row in the data so I have a couple of questions as I know it’s possible to do as there is already a faucet feature which works the same way basically.

    How would I go about giving a user X amount of coins? If I were to make a dummy account and use his account Id as the sender, could that work or would it’s account go negative and mess things up on my site when it tries to send more coins when it’s account worth is negative? Or is Negative not going to glitch as it’s just a negative integer on a dummy account that no one will use or send to?

    The main goal of this is so that I could allow users to gain currencies by watching ads or playing approved games to earn coins to exchange for things on my shop and some extras like gift cards to food places or gaming platforms for a month or 2.

    #11492
    alexg
    Keymaster

    Hello,

    You should not manipulate the wp_wallets_txs table directly for a number of reasons. Mainly, the table is going to be removed in the next major version 6.0.0 of the plugin. You are quite right that the table is kinda weird; in fact, in the past I have ranted about how bad this is, and I’m looking forward to get rid of it!

    Instead, to create a transfer, you can use the wallets_api_move action from the PHP API:

    https://wallets-phpdoc.dashed-slug.net/classes/Dashed_Slug_Wallets_PHP_API.html#method_api_move_action. This PHP API will be preserved in future versions of the plugin.

    A gaming service is a very interesting application. If I may ask, are you developing this for use on your site only, or is it something that you plan to publish/sell somewhere?

    with regards

    https://mail.zoho.com/zm/#mail/folder/inbox/p/1645276382613100001

    Hello,

    Yes this is a typical problem. Hopefully there will not be any such issues once the WP-REST API becomes available. In the meantime, look into your cashing plugin and see if you can disable

    #11520
    Anonymous
    Inactive

    You’re not joking when you say it’s bad. It’s kinda horrible and I was just like ‘oh s**t’ when I saw it. That do_action call is going to work perfect, I just built a rpc function to let me call it by RPC which works better than trying to do more SQL lol (hasn’t tested yet tho). Thank you very much for your help, you’re a G bro.

    The gaming service I have been debating because I built my own encryption method that takes a String to convert it to a Int based on a ‘Key file’ than run that Int into a ‘Equation file’ that will contain different types of math to either encrypt the Int or to decrypt it for the String so the issue I kinda have is if you never routinely modified your files than it would be possible for someone to have programs to read incoming and outgoing data and maybe taking 2 years could figure out some or all of how your encryption is done based on certain words. I was thinking about at first offering a service that you would run a new python file in the background that contains your database information and game cloud data you could want and have clients to use my master so that encryption would be routinely (daily) changed by AI so ‘Hello World’ would have a different value everyday based on every ‘Key File’ ‘Equation File’ pair possible than at some point testing a new python script that would act like it’s own master but could use the same keys on my official master.

    I got it working as I bought a half made City Builder (Clash of Clans style) and have been able to login/register users AND setup key based value saving to a database which is used in c# like “BAServiceController.GetValue(“KEY NAME HERE”);” which would return the value of the information stored under that key through html which could have the encryption turned off or on based on if that information needs to be kept hidden but I don’t currently encrypt anything besides the user information because I don’t care if people see the json structure of the game I bought to test with, with a change of a variable tho it would encrypt when sending.

    #11521
    Anonymous
    Inactive

    Is there a way to give a account my custom coin from the fiat adapter? Everyone’s account is currently sitting at 0 and I would like to give a admin account all the coins which will be distributed from itself.

    #11524
    alexg
    Keymaster

    Hello,

    Thanks for sharing your plans. I’m not sure you’re using the word encryption correctly. I am not using any encryption in the plugins, as it’s not relevant. If you are referring to JSON-API calls, these are secured by TLS against eavesdropping, man-in-the-middle and replay attacks, but that’s got nothing to do with the plugin code.

    I also didn’t understand whether you will make your work available to others or whether it’s for use in your site only. In any case, I wish you the best of luck with your project!

    Giving coins is not related to coin adapters. To modify the ledger, use the wallets_api_move action as discussed above. This will let you transfer any type of coins from the admin account, whether they were introduced using the fiat adapter or not.

    with regards

    #11535
    Anonymous
    Inactive

    Actually bro, I cant just send coins as an admin account with no coins. I want to know how to I can ‘add/create’ my custom fiat coins to a account so I can send them? It’s basically just a virtual currency that I want to add to accounts but my admin account has 0

    #11536
    Anonymous
    Inactive

    You have attempted to send LETS 20.00 from your account to the Austin Benjamin account.

    Your transaction failed after being attempted a predetermined number of times and will not be retried any further. If you are unsure why your transaction failed, please contact the administrator.

    Coin symbol: LETS
    Amount: LETS 20.00 (in USD: n/a)
    Fees: LETS 0.00 (in USD: n/a)
    Amount after fees: LETS 20.00 (in USD: n/a)
    Transaction ID: **ID WAS HERE**
    Transaction created at: 2022-03-01 19:28:45
    Comment: Rolled: 77
    Tags: send wallets-faucet payout

    #11537
    alexg
    Keymaster

    OK I understand your point.

    You could try and insert a fake “deposit” row for your admin user to the transactions table. For example, assuming your DB table prefix is wp_, and assuming you are not on multisite, you could do something like the following in your MySQL console:

    INSERT INTO wp_wallets_txs (
        category,
        tags,
        account,
        address,
        txid,
        symbol,
        amount,
        created_time,
        updated_time,
        status
    )
    
    VALUES (
    	'deposit',
    	'foo bar', -- you can use any tags here to help you keep track of your deposits
    	1, -- assume this is your admin account's user_id
    	'', -- address is not neeed
    	UUID(), -- the txid value needs to be unique
    	'LETS',
    	100000, -- money printer goes brrr
    	current_time(),
    	current_time(),
    	'done'
    );

    But that’s probably not the easiest way.

    The easiest way would be to use the Airdrop extension. You can perform an airdrop of a fixed amount of any coin to a user role. If you are the only administrator and you do an airdrop on the administrators role, then your admin user will receive one “deposit”. You can then proceed to distribute these coins.

    Install the Airdrop extension, then go to ToolsAirdrop to perform an immediate airdrop.

    Hope this helps. Let me know if you face any problems doing this.

    with regards

    P.S. In the upcoming release I have addressed this, and it will be very easy to create/edit transactions in the local ledger via the admin screens. You’ll see!

    #11540
    Anonymous
    Inactive

    Not going to lie, I would really love to see that feature. Thank you for your help and you nailed it for me, by seeing kaymaster I’m assuming Dashed Slug is yours and you’re doing great man! Everything came out perfect.

    #11543
    alexg
    Keymaster

    I’ve tried to add as many user requests into the upcoming release, prioritizing those that help with usability, and that are feasible on my part within a realistic time frame.

    The release is delayed primarily due to the difficulties of managing gas fees on the CoinPayments platform. Just yesterday late at night I ran some successful live tests of my gas-distributing algo on the Ethereum blockchain. Now I just need to try to adapt this to BC Chain (BEP2) and BSC Chain (BEP20). I will have to leave Solana and Tron for a later time after the release, but at least the CoinPayments adapter is now able to be extended towards new blockchains with fees that require gas to deposit…

    Thank you for your kind words on behalf of the entire dashed-slug team! :p

    #11563
    Anonymous
    Inactive

    So I ran into another issue and wonder if you could help me. I got everything working and during testing I got stuck on the actual sending part. It seems that it keeps trying to send the funds to the same user even tho I have specified a ID to send the funds to. So I have a Client (Postman, running post requests) and I am getting the server to send the funds which uses Python-WordPress-XMLRPC to send WP do_action. Everything seems like it should work but keeps returning the same thing, maybe I did something wrong?

    #11564
    Anonymous
    Inactive

    -=- PYTHON CODE – x[1] = USER ID … data[] = server sided variables like login, reward amount and reserve ID -=-

    ww = clienter.call(getReward(str(x[1]), ‘LETS’, str(data[“reward”])))
    return ‘SENT BY ‘ + data[“reserve_id”] + ‘ SENT TO ‘ + str(x[1]) + ‘ WITH ‘ + str(data[“reward”]) + ‘ RETURNED ‘ + ww

    RETURNED DATA

    SENT BY 10523 SENT TO 10537 WITH 10 RETURNED Cannot send funds to self`

    #11565
    Anonymous
    Inactive

    function mynamespace_getReward( $args ) {
    try{
    do_action( ‘wallets_api_move’, array(‘symbol’ => (string) $args[1],’amount’ => (float) $args[2],’to_user_id’ => (int) $args[0],’skip_confirm’ => true) );
    return “true”;
    }catch (Exception $e) {
    return $e->getMessage();
    }
    }

    #11567
    Anonymous
    Inactive

    Got it figured out, ‘from_user_id’ wasn’t optional with XMLRPC I guess. So far I can’t send to the admin account (because the id is zero/0) but all the other accounts seem to be working as of right now. I was able to transfer 200 LETS from the reserve account into a dummy membership account I had and it all works. I see now it’s extremely easy to make very cool applications. Buddypress picks up the action and automatically will send messages about it to users, I’m not sure if I will keep that enabled.

    #11568
    alexg
    Keymaster

    Hello,

    Glad you figured the issue out.

    The admin’s user_id is not 0, it should be 1 by default.

    I think WordPress starts counting from 1 because in MySQL, the primary keys for users, posts, etc are defined as AUTO_INCREMENT columns, and AUTO_INCREMENT columns start from 1.

    In fact, if you are certain that the user_id of the admin is 0, you may be facing bigger problems, caused by improperly exporting and reimporting a database via phpMyAdmin. I have blogged about it here. Are you able to create new posts? If not, you may be ecountering this issue.

    Hope this helps.

Viewing 15 posts - 1 through 15 (of 17 total)
  • You must be logged in to reply to this topic.