Difference between revisions of "Installing the run sdk"

From RunWiki
Jump to: navigation, search
 
(30 intermediate revisions by the same user not shown)
Line 1: Line 1:
<p>The easiest way to get the latest version is to run '''<code class="mwt-code">npm install run-sdk</code>'''</p>
+
{| style="border-collapse:collapse; background-color:red;"
 +
| style="padding:10px; text-align:center; font-weight:bold; color:white;" |
 +
ALERT: This Page is Outdated and Waiting for Update
 +
The current way of testing the RUN library to create tokens is to open the devtools console at [https://runcraft.io Runcraft.io], then head over to [[Creating_and_loading_jigs|creating and loading jigs]].
 +
|}
  
Another solution is to download the SDK as a zip file from [https://run.network/ https://run.network/]. When writing this the latest version is [https://github.com/runonbitcoin/sdk/archive/refs/tags/v0.6.37.zip version 0.6.37].
+
 
 +
 
 +
The easiest way to get the latest version is to run
 +
<pre>
 +
[deprecated, instead retrieve the compiled sdk file from runcraft.io] npm install run-sdk
 +
</pre>
 +
 
 +
&nbsp;Another solution is to download the SDK as a file from [https://runcraft.io/ https://runcraft.io]. At the time of writing the latest version is 0.6.37
  
 
= Getting Started =
 
= Getting Started =
  
(note the following section was originally a simple copy/paster from [https://run.network/docs/#getting-started the official doc])
+
== Installation ==
  
== Installation ==
+
If you're new to Run, let the [https://run.network/lessons tutorial series] guide your journey to get acquainted. You can write code without installing anything. The web browser Console will be your playground.
 +
 
 +
The details written here in the Docs have example code in the sidebar on the right-hand side. Anything you read in paragraphs, you can preview in-action over there.
 +
 
 +
Run works everywhere including all major browsers, on desktop and mobile, as well as Node.js 10+ on servers. The Run SDK is written in JavaScript ES6 and uses the [https://github.com/moneybutton/bsv bsv library] to build and sign transactions. To get started:
 +
 
 +
*For a webpage: Add <code>bsv.browser.min.js</code> and <code>run.browser.min.js</code> to the <code><head></code> tag.
 +
*For Node.js: Run <code>npm install run-sdk</code> to install both the run and bsv libraries
 +
And that's it. All your code and jigs will be saved on-chain and Run will use public APIs to interact with the Bitcoin network. You don't need to deploy any servers to use Run. All the logic works client-side.
 +
 
 +
You can also find the SDK at [https://github.com/runonbitcoin/sdk the github repo].
 +
 
 +
=== Code ===
 +
 
 +
Load both bsv and run in the browser
 +
 
 +
<syntaxhighlight lang="html">
 +
<script src="https://unpkg.com/bsv@1.5.6"></script>
 +
<script src="https://unpkg.com/run-sdk"></script>
 +
</syntaxhighlight>
  
<p>If you're new to Run, let the&nbsp;</p>[https://run.network/lessons tutorial series]<p>&nbsp;guide your journey to get acquainted. You can write code without installing anything. The web browser Console will be your playground.</p><p>The details written here in the Docs have example code in the sidebar on the right-hand side. Anything you read in paragraphs, you can preview in-action over there. ⇥</p><p>Run works everywhere including all major browsers, on desktop and mobile, as well as Node.js 10+ on servers. The Run SDK is written in JavaScript ES6 and uses the&nbsp;</p>[https://github.com/moneybutton/bsv bsv library]<p>&nbsp;to build and sign transactions. To get started:</p>
+
Load run in Node.js
*For a webpage: Add&nbsp;<code>bsv.browser.min.js</code>&nbsp;and&nbsp;<code>run.browser.min.js</code>&nbsp;to the&nbsp;<code>&lt;head&gt;</code>&nbsp;tag.
+
<syntaxhighlight lang="javascript">
*For Node.js: Run&nbsp;<code>npm install run-sdk</code>&nbsp;to install both the run and bsv libraries
+
const Run = require('run-sdk')
<p>And that's it. All your code and jigs will be saved on-chain and Run will use public APIs to interact with the Bitcoin network. You don't need to deploy any servers to use Run. All the logic works client-side.</p>
+
</syntaxhighlight>
  
 
== Setup ==
 
== Setup ==
 +
A <code>Run</code> instance manages your communication with the Bitcoin network. The default network is <code>main</code> (Mainnet), but for development and testing, we recommend <code>mock</code>. Mock is an in-memory simulation blockchain that does not require funds to use. We like to call it the mockchain. For more configuration options, see [https://run.network/docs/#api-reference-run API Reference: Run.]
  
A <code>Run</code> instance manages your communication with the Bitcoin network. The default network is <code>main</code> (Mainnet), but for development and testing, we recommend <code>mock</code>. Mock is an in-memory simulation blockchain that does not require funds to use. We like to call it the ''mockchain''. For more configuration options, see [https://run.network/docs/#api-reference-run API Reference: Run].
+
=== Code ===
 
 
== Creating Jigs ==
 
  
<p>Let's begin with a basic jig that stores a value in a variable. Create a jig called&nbsp;<code>SimpleStore</code>. By extending from&nbsp;<code>Jig</code>, the instances of your class will automatically sync to the blockchain. Every jig has an&nbsp;<code>owner</code>. Any code may read jigs but only its&nbsp;<code>owner</code>&nbsp;can update it. The&nbsp;<code>owner</code>&nbsp;is typically a Bitcoin address, and the private key is required to update it.</p><p>In addition to&nbsp;<code>owner</code>, every jig has a&nbsp;<code>location</code>. A jig's&nbsp;<code>location</code>&nbsp;is the pairing of a Bitcoin transaction ID and an output index, and it represents a particular state in time of an object or class on Bitcoin. When you check the&nbsp;<code>location</code>&nbsp;property of a jig, you get its current location. If you wish to get the location where the jig was first deployed, that is called its&nbsp;<code>origin</code>. The&nbsp;<code>origin</code>&nbsp;is unique and will not change, however&nbsp;<code>location</code>&nbsp;changes with every update. After a method call, your jig will have a new&nbsp;<code>location</code>&nbsp;pointing to a Bitcoin transaction containing the last method call.</p>
+
<syntaxhighlight lang="javascript">
 +
const run = new Run({ network: 'mock' })
 +
</syntaxhighlight>
  
== Loading Jigs ==
+
<p>After that you are ready to [[Creating and_loading_jigs|create and load jigs]].</p>
  
<p>The simplest way to load your jigs is to call&nbsp;<code>run.inventory.sync()</code>&nbsp;and then access&nbsp;<code>run.inventory.jigs</code>.&nbsp;<code>run.inventory.sync()</code>&nbsp;will find and load all objects owned by&nbsp;<code>run.owner</code>&nbsp;and place them in the&nbsp;<code>jigs</code>&nbsp;array. Once loaded, you may call methods and use them normally. Alternatively, you may wish to load a particular jig or load a jig in a historical state. To do either, pass the&nbsp;<code>location</code>&nbsp;of the jig you wish to load into&nbsp;<code>run.load()</code>.</p><p>If you've loaded a historical location so that your jig is in a previous state, you'll need to first catch up to the latest state before you'll be allowed to make a method call.&nbsp;<code>sync()</code>&nbsp;will handily fast-forward a jig to its latest state on the blockchain&nbsp;''without''&nbsp;triggering a Bitcoin transaction. In the example on the sidebar, if&nbsp;<code>specificJig</code>&nbsp;was in a historical state, you would call&nbsp;<code>specificJig.sync()</code>&nbsp;and then call&nbsp;<code>specificJig.set('abc')</code>. When you accidentally try to update a jig without the jig being in its latest state, Run will safely abort before publishing a Bitcoin transaction and inform you with an error. In that case, you'll just need to add the preceding&nbsp;<code>sync()</code>&nbsp;call and execute your code again. The best practice is to write code in such a way that jigs are always up-to-date in their latest state. Run manages the heavy lifting for you.</p><p><code>sync()</code>&nbsp;also acts as a debugging tool since it surfaces any errors your jigs have after you've made changes to them. If you notice your app acting funny, a well-placed preceding&nbsp;<code>specificJig.sync()</code>&nbsp;can help you uncover the error. You may also call&nbsp;<code>sync()</code>&nbsp;on your&nbsp;<code>Run</code>&nbsp;instance, like this:&nbsp;<code>run.sync()</code>. That'll help you search out any errors from your entire app in&nbsp;''all''&nbsp;of the jigs you own.</p>
+
[[Category:Documentation]]

Latest revision as of 03:23, 2 March 2025

ALERT: This Page is Outdated and Waiting for Update The current way of testing the RUN library to create tokens is to open the devtools console at Runcraft.io, then head over to creating and loading jigs.


The easiest way to get the latest version is to run

[deprecated, instead retrieve the compiled sdk file from runcraft.io] npm install run-sdk

 Another solution is to download the SDK as a file from https://runcraft.io. At the time of writing the latest version is 0.6.37

Getting Started

Installation

If you're new to Run, let the tutorial series guide your journey to get acquainted. You can write code without installing anything. The web browser Console will be your playground.

The details written here in the Docs have example code in the sidebar on the right-hand side. Anything you read in paragraphs, you can preview in-action over there.

Run works everywhere including all major browsers, on desktop and mobile, as well as Node.js 10+ on servers. The Run SDK is written in JavaScript ES6 and uses the bsv library to build and sign transactions. To get started:

  • For a webpage: Add bsv.browser.min.js and run.browser.min.js to the <head> tag.
  • For Node.js: Run npm install run-sdk to install both the run and bsv libraries

And that's it. All your code and jigs will be saved on-chain and Run will use public APIs to interact with the Bitcoin network. You don't need to deploy any servers to use Run. All the logic works client-side.

You can also find the SDK at the github repo.

Code

Load both bsv and run in the browser

<script src="https://unpkg.com/bsv@1.5.6"></script>
<script src="https://unpkg.com/run-sdk"></script>

Load run in Node.js

const Run = require('run-sdk')

Setup

A Run instance manages your communication with the Bitcoin network. The default network is main (Mainnet), but for development and testing, we recommend mock. Mock is an in-memory simulation blockchain that does not require funds to use. We like to call it the mockchain. For more configuration options, see API Reference: Run.

Code

const run = new Run({ network: 'mock' })

After that you are ready to create and load jigs.