SDK
Instructions for testing the SDKs.
The following procedure should be done within the skynet-js
repo.
You may want to create a new branch to avoid committing the following changes.
Create index.html
in root with some buttons to trigger functions you want to test:
<html>
<body>
<input type="button" value="Download" id="download"/>
<input type="file" id="mediaFile">
<input type="button" value="Upload" id="upload"/>
<script type="application/javascript" src="./dist/main.js"></script>
</body>
</html>
src/index.ts
(don't commit this):
import { SkynetClient } from "./client";
const client = new SkynetClient("https://siasky.net");
const skylink = "CABqlFxQyimh292KJlqp-7HMA_vypPnSCoB-QZjzG5ObHw";
document.getElementById("download").addEventListener("click", function () {
client.downloadFile(skylink);
});
document.getElementById("upload").addEventListener("click", function () {
const file = (<HTMLInputElement>document.getElementById('mediaFile')).files[0];
client.uploadFile(file);
});
yarn add -D webpack webpack-cli
webpack.config.js
file:
module.exports = {
mode: "development",
entry: "./dist",
output: {
library: "skynet-js",
libraryTarget: "umd",
umdNamedDefine: true,
},
target: "web",
};
yarn build
yarn run webpack
python3 -m http.server
Attend
http://localhost:8000/
in your browser.
test.js
:
const { SkynetClient } = require("./index.js");
const client = new SkynetClient();
async function uploadResponse() {
const filename = "README.md";
try {
console.log(filename);
const skylink = await client.uploadFile(filename);
console.log(skylink);
} catch (error) {
console.log(error);
}
}
uploadResponse();
node test.js
test.py
:
import siaskynet as skynet
client = skynet.SkynetClient()
filename = "tmp-91161-Kw39pPEcTxAZ-.json"
skylink = client.upload_file(filename)
print("Upload successful, skylink: " + skylink)
pipenv run python test.py
main/
with the main
package:package main
import (
"fmt"
skynet "github.com/NebulousLabs/go-skynet/v2"
)
// create a client
var client = skynet.NewCustom("http://localhost:9980", skynet.Options{})
func main() {
// upload
opts := skynet.DefaultUploadOptions
opts.SkykeyName = "key_to_the_castle"
skylink, err := client.UploadFile("./unencrypted.txt", opts)
if err != nil {
panic("Unable to upload: " + err.Error())
}
fmt.Printf("Upload successful, skylink: %v\n", skylink)
// download
err = client.DownloadFile("./encrypted.txt", skylink, skynet.DefaultDownloadOptions)
if err != nil {
panic("Something went wrong, please try again.\nError: " + err.Error())
}
fmt.Println("Download successful")
}
go run main/main.go
or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing