I was playing with Web Maker App as an alternative to codepen , and have been meaning to actually do something with the chain.
I remember I have this obsession with custom_json and how useful it can be but wanted to do it in vanilla js. I also completely over-engineered what I would do etc.
Today I just did not. I just hacked together some pieces and went for it. This is the horrifying tale of that.
Imagine the most simple, horrible html form you can then beat it with a brick. The html I added was just to have a semblance to a DOM instead of hardcoding everything. Which I did anyway with the message I sent, F the man.
//HTML
<form>
<input id="account" type="text" placeholder="account name" name="account">
<input id="key" type="password" placeholder="posting Key" name="key">
<button id="doshit">Do Shit</button>
<button id="domoreshit">Send that shit</button>
</form>
Since Web Maker App links the libraries for us there is no need for a local file and script hassles. It is simple enough to actually take the data and put it in the required structure even by just getting the info from a direct call to the api without using any libraries. I sooooooo wanted to try it vanilla, these libraries are hard.
Then I looked at the authentication helpers to broadcast the transaction to the chain and pissed myself a little.
In the app you may proceed and link the Dsteem library , use a version below 0.11.0 else shit is just fucked up. So that is from version ^0.8.0 - ^0.10.0
Now, this is not pretty, I promise you it is not a tutorial or anything. It is just something that had to be done.
//JAVASCRIPT
//set up steem client.
const client = new dsteem.Client('https://api.steemit.com');
//stuff to send in transaction
//use account name as unique prefix and because I like my name ok.
let transactionBody = {
id: "penderis_sos",
json: "",
required_auths: [],
required_posting_auths: []
}
//When is the party, is clothing optional? This is the data we care about
let jsonBody = {
call: "penderis",
why: "for a good time",
when: "horny"
}
//it is a funny word no idea wtf it means I actually hate it
//just say private key you prick
let wif
let doshit = document.getElementById('doshit');
//make it if we clicky it then it speaky to the thingy
doshit.addEventListener('click', function(event){
event.preventDefault();
//trigger get the shitty info and doing stuff via the event listener
//because I am not going to build out form inputs fuck that shit.
//ok maybe I will. fuckit
let accountName = document.getElementById('account').value;
let accountKey = document.getElementById('key').value;
//dsteem will take your text and make it special or you get a useless error
wif = dsteem.PrivateKey.from(accountKey);
//probably should not use push, but tell me when will I ever in
//my fucking in life require multiple names to sign this shit.
//But probably should not use push or it will be wrong
transactionBody.required_posting_auths.push(accountName);
transactionBody.json = JSON.stringify(jsonBody);
//shall we see if this updates the variables.
console.log(transactionBody);
})
let domoreshit = document.getElementById("domoreshit");
//make it so when we clicky it then it listens to the speaky and tattles
domoreshit.addEventListener('click',function(event){
event.preventDefault();
//Sign, seal and hopefully deliver everything we heard.
client.broadcast.json(transactionBody,wif).then(
function(result){
console.log(result);
},
function(error){
console.log(error);
}
)
})
Now I looked before posting but I don't actually think I can just go and index these things without streaming blocks or some shit. Which begs the question. Ok not a question just a random thought. Nah, this typing thing is getting boring and I think I just realized that the only use for the chain is to monetize. I do feel better posting a few words also though, not a complete gold digger. I will whisper sweet nothings also.
I like that you've put comments in your code. Way to go!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit