@acryl/acryl-repl 中文文档教程

发布于 5年前 浏览 16 项目主页 更新于 3年前

REPL

About

此存储库包含 acryl 区块链的 javascript 控制台。 它建立在 jsconsole 之上,并具有与 acryl 一起使用的预定义功能

Builtin functions

JS lib

控制台使用 acryl-transactions 库。 顶级库函数绑定到控制台全局范围。 不同之处在于,在控制台中,seed 参数默认等于 env.SEED。 如果您只想创建交易而不想签署交易,则需要显式传递 null 示例:

Console
const signedTx = transfer({amount: 100, recipient: '3MyAGEBuZGDKZDzYn6sbh2noqk9uYHy4kjw', senderPublicKey: '8ViwGfvyyN1teUKV4Uvk2orK6XiYB4S4VuM2DqJ9Mj5b'}, null)

//returns tx with no proofs
{
  "type": 4,
  "version": 2,
  "fee": 100000,
  "senderPublicKey": "8ViwGfvyyN1teUKV4Uvk2orK6XiYB4S4VuM2DqJ9Mj5b",
  "timestamp": 1542640481876,
  "proofs": [],
  "id": "CveeKH16XQcshV5GZP2RXppg3snxcKqRsM4wE5gxcuzc",
  "chainId": "K",
  "amount": 100,
  "recipient": "3MyAGEBuZGDKZDzYn6sbh2noqk9uYHy4kjw"
}

Additional functions

使用来自全局变量的节点广播已签名的 tx 使用来自全局变量的节点

const resp = await broadcast(signedTx)

部署当前开放合约

const resp = deploy()

签署任意交易

const tx = transfer({amount: 100, recipient: '3MyAGEBuZGDKZDzYn6sbh2noqk9uYHy4kjw', senderPublicKey: '8ViwGfvyyN1teUKV4Uvk2orK6XiYB4S4VuM2DqJ9Mj5b'}, null)
const signedTx = signTx(tx)

编译合约。 返回 base64

const compiled = compile(contractText)

通过选项卡名称获取合同文本。 在 web-ide 或 vscode 插件

const contractText = file(tabName)

中使用从当前打开的选项卡获取合同文本。 在 web-ide 或 vscode 插件中使用

const contractText = contract()

Keys

address(seed = env.SEED) // Address from seed. 
keyPair(seed = env.SEED) // Keypair from seed
publicKey(seed = env.SEED) // Public key from seed
privateKey(seed = env.SEED) // Private key from seed

Global object env

env.SEED // Default seed
env.CHAIN_ID // Default network byte
env.API_BASE // Node url 
env.editors // Open editor tabs info

Usage

Dev server:

npm start

启动开发服务器

React component

```typescript jsx 从“反应”导入*作为反应; 从'react-dom'导入{render}; 从'acryl-repl'导入{Repl};

类 App 扩展 React.Component { public consoleRef = React.createRef();

componentDidMount(){
    // Get console instance
    const console = this.consoleRef.current!;

    // Access to console api
    (global as any)['updateEnv'] = console.updateEnv;
    (global as any)['API'] = console.API;
    (global as any)['methods'] = console.methods;

    (global as any)['updateEnv']({
        SEED: 'abracadabra',
        API_BASE: 'https://nodestestnet.acrylplatform.com',
        CHAIN_ID: 'K',
        file: () => 'Placeholder file content'
    });

}
render(){
    return <Repl theme="dark" ref={this.consoleRef}/>
}

} 渲染(,document.getElementById('root')); ```

REPL

About

This repository contains javascript console for acryl blockchain. It is built on top of jsconsole and have predefined functions to work with acryl

Builtin functions

JS lib

Console uses acryl-transactions library. Top level library functions are bound to console global scope. The difference is that in console, seed argument is equal to env.SEED by default. You need to pass null explicitly if you only want to create transaction and not to sign it E.x.:

Console
const signedTx = transfer({amount: 100, recipient: '3MyAGEBuZGDKZDzYn6sbh2noqk9uYHy4kjw', senderPublicKey: '8ViwGfvyyN1teUKV4Uvk2orK6XiYB4S4VuM2DqJ9Mj5b'}, null)

//returns tx with no proofs
{
  "type": 4,
  "version": 2,
  "fee": 100000,
  "senderPublicKey": "8ViwGfvyyN1teUKV4Uvk2orK6XiYB4S4VuM2DqJ9Mj5b",
  "timestamp": 1542640481876,
  "proofs": [],
  "id": "CveeKH16XQcshV5GZP2RXppg3snxcKqRsM4wE5gxcuzc",
  "chainId": "K",
  "amount": 100,
  "recipient": "3MyAGEBuZGDKZDzYn6sbh2noqk9uYHy4kjw"
}

Additional functions

Broadcast signed tx using node from global variable

const resp = await broadcast(signedTx)

Deploy current open contract using node from global variable

const resp = deploy()

Sign arbitrary transaction

const tx = transfer({amount: 100, recipient: '3MyAGEBuZGDKZDzYn6sbh2noqk9uYHy4kjw', senderPublicKey: '8ViwGfvyyN1teUKV4Uvk2orK6XiYB4S4VuM2DqJ9Mj5b'}, null)
const signedTx = signTx(tx)

Compile contract. Returns base64

const compiled = compile(contractText)

Get contract text by tab name. Used inside web-ide or vscode plugin

const contractText = file(tabName)

Get contract text from currently open tab. Used inside web-ide or vscode plugin

const contractText = contract()

Keys

address(seed = env.SEED) // Address from seed. 
keyPair(seed = env.SEED) // Keypair from seed
publicKey(seed = env.SEED) // Public key from seed
privateKey(seed = env.SEED) // Private key from seed

Global object env

env.SEED // Default seed
env.CHAIN_ID // Default network byte
env.API_BASE // Node url 
env.editors // Open editor tabs info

Usage

Dev server:

npm start

Starts dev server

React component

```typescript jsx import * as React from 'react'; import {render} from 'react-dom'; import {Repl} from 'acryl-repl';

class App extends React.Component { public consoleRef = React.createRef();

componentDidMount(){
    // Get console instance
    const console = this.consoleRef.current!;

    // Access to console api
    (global as any)['updateEnv'] = console.updateEnv;
    (global as any)['API'] = console.API;
    (global as any)['methods'] = console.methods;

    (global as any)['updateEnv']({
        SEED: 'abracadabra',
        API_BASE: 'https://nodestestnet.acrylplatform.com',
        CHAIN_ID: 'K',
        file: () => 'Placeholder file content'
    });

}
render(){
    return <Repl theme="dark" ref={this.consoleRef}/>
}

} render(, document.getElementById('root')); ```

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文