Wordpress Interface with Hive Keychain.

View this thread on: d.buzz | hive.blog | peakd.com | ecency.com
·@diggndeeper.com·
0.000 HBD
Wordpress Interface with Hive Keychain.
<center>https://diggndeeper.com/wp-content/uploads/2020/03/cropped-logo-2k.png</center> <br/><figure class="wp-block-embed is-type-wp-embed is-provider-diggndeeper wp-block-embed-diggndeeper"><div class="wp-block-embed__wrapper">
https://diggndeeper.com/wp-dapp/
</div></figure>
<p><a rel="noreferrer noopener" class="keychainify-checked" href="https://hive-keychain.com/" target="_blank">Hive Keychain</a> integration requires the Hive Keychain API. </p>
<ol><li>Register with Hive Keychain API. Provide information such as your application name, description, and callback URL.</li>
<li>Hive Keychain API requests permission from users to access their Hive accounts. Use the <code>hive_keychain_requestPermission</code> function to prompt the user to grant permission.</li>
<li>After the user has granted permission, you can use the <code>hive_keychain_broadcast</code> function to broadcast transactions to the Hive blockchain. You will need to pass in the transaction object and the user's account name and permission.</li>
<li>You can also use the <code>hive_keychain_signBuffer</code> function to sign messages with the user's private key.</li>
</ol>
<p><a rel="noreferrer noopener" class="keychainify-checked" href="https://cloud.diggndeeper.com/index.php/s/Wcd2PPorBTBPNQt" target="_blank">wp-dapp.php</a> on Nextcloud</p>
<pre class="wp-block-code"><code>&lt;?php
/**
 * Plugin Name: wp-dapp
 * Description: Hive Keychain API
 * Version: .0.0
 */

// Add the Hive Keychain API script to the header
function add_hive_keychain_api_script() {
    wp_enqueue_script( 'hive-keychain-api', 'https://cdn.jsdelivr.net/npm/hive-keychain-api@1.2.0/index.js', array(), null, true );
}
add_action( 'wp_enqueue_scripts', 'add_hive_keychain_api_script' );

// Add a shortcode that displays a form to post a message to Hive
function hive_post_form_shortcode() {
    ob_start();
    ?&gt;
    &lt;form id="hive-post-form"&gt;
        &lt;input type="text" name="message" placeholder="Enter your message"&gt;
        &lt;button type="submit"&gt;Post to Hive&lt;/button&gt;
    &lt;/form&gt;
    &lt;div id="hive-post-result"&gt;&lt;/div&gt;
    &lt;script&gt;
        // Handle form submission
        document.getElementById( 'hive-post-form' ).addEventListener( 'submit', function( event ) {
            event.preventDefault();
            // Get the user's Hive account name and permission from Hive Keychain
            hive_keychain.requestAccount( function( account ) {
                if ( ! account ) {
                    alert( 'Please install and authorize Hive Keychain to use this feature.' );
                    return;
                }
                // Get the message from the form input
                var message = document.querySelector( 'input&#91;name="message"]' ).value;
                // Construct the Hive transaction object
                var tx = {
                    'operations': &#91;&#91;
                        'comment',
                        {
                            'parent_author': '',
                            'parent_permlink': 'test',
                            'author': account.name,
                            'permlink': 'my-post',
                            'title': '',
                            'body': message,
                            'json_metadata': '{}'
                        }
                    ]]
                };
                // Broadcast the transaction to Hive
                hive_keychain.broadcast( account.name, 'posting', tx, function( response ) {
                    if ( response.success ) {
                        document.getElementById( 'hive-post-result' ).innerHTML = 'Your message was posted to Hive!';
                    } else {
                        document.getElementById( 'hive-post-result' ).innerHTML = 'There was an error posting your message to Hive.';
                    }
                });
            });
        });
    &lt;/script&gt;
    &lt;?php
    return ob_get_clean();
}
add_shortcode( 'hive_post_form', 'hive_post_form_shortcode' );</code></pre>
<p>This code does the following:</p>
<ul><li>Adds the Hive Keychain API script to the header of the plugin's pages.</li>
<li>Defines a shortcode <code>hive_post_form</code> that displays a form to post a message to Hive.</li>
<li>Uses the <code>hive_keychain.requestAccount</code> function to get the user's Hive account name and permission.</li>
<li>Constructs a Hive transaction object that posts the message to the <code>test</code> tag on the Hive blockchain.</li>
<li>Uses the <code>hive_keychain.broadcast</code> function to broadcast the transaction to Hive.</li>
</ul>
<ol start="3"><li>Save the <code>wp-dapp.php</code> file and activate the plugin in</li>
</ol>
<p>We can store the files on our <a rel="noreferrer noopener" class="keychainify-checked" href="https://cloud.diggndeeper.com" target="_blank">Nextcloud Hub</a>. This hub needs work. It is cloud hosted and limited and I would really like to build a <a class="keychainify-checked" href="https://diggndeeper.com/node-master/" data-type="post" data-id="255">Node Master</a> connected to <a href="http://mesh" data-type="URL" data-id="mesh">Meshnets</a> to solve all our development problems. </p>
 <br /><center><hr/><em>Posted from my blog with <a href='https://wordpress.org/plugins/exxp/'>Exxp</a> : https://diggndeeper.com/wordpress-interface-with-hive-keychain/ </em><hr/></center>
👍 , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,