How to use the @cityofzion/neon-js.create function in @cityofzion/neon-js

To help you get started, we’ve selected a few @cityofzion/neon-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github be-neo / neoblog / packages / smart-contract-js-lib / src / getfromstorage.js View on Github external
import '@babel/polyfill';
import Neon, { api, u } from '@cityofzion/neon-js';
import { scriptHash, localHost } from './blockchain/config';

const client = Neon.create.rpcClient(localHost);
const s2h = u.str2hexstring;

const store_key = u.str2hexstring('post.')+u.int2hex(1);

/* (async function main() {
  queryBlockchain(store_key).then((result) => {
    console.log(result);
  }).catch((e) => {
    console.log(e);
  });
})(); */

export default function queryBlockchain(key) {
  const query = Neon.create.query({
    'method': 'getstorage',
    'params': [
github PacktPublishing / Foundations-of-Blockchain / Chapter07 / NEO / proof_of_ownership_app / interface / src / App.js View on Github external
let invoke = {

                scriptHash: '60a7ed582c6885addf1f9bec7e413d01abe54f1a',

                operation: 'register',

                args: [

                    'asdsd'.hexEncode(),
                    'AK2nJJpJr6o664CWJKi1QRXjqeic2zRp8y'.hexEncode()

                ]

            }

            let sb = Neon.create.scriptBuilder();

            sb.emitAppCall(invoke.scriptHash, invoke.operation, invoke.args, false);
            let script = sb.str;
            let unsignedTx = Neon.create.invocationTx();


            let signedTx = unsignedTx.addIntent(intents).sign(account.privateKey);
            console.log(signedTx)

            // send the transaction to our net

            rpc.queryRPC('http://139.59.25.30:30333', {

                method: 'sendrawtransaction',

                params: [signedTx],
github be-neo / neoblog / packages / smart-contract-js-lib / src / invokesmartcontract.js View on Github external
export default async function main() {
  // Actual invoke params
  const account = Neon.create.account(privnetWif);
  const invoke = createInvoke(operation, args);
  const gasCost = 0;
  const intents = [
    { assetId: assets.GAS, value: 0.00000001, scriptHash: Neon.get.scriptHashFromAddress(account.address)}
  ];

  // Test invoke
  const testResponse = await testInvoke(invoke);
  if (testResponse.result.gas_consumed < 10) {
    const invokeResponse = await executeInvoke(account, invoke, gasCost, intents);
    console.log(invokeResponse);
  }
};
github be-neo / neoblog / packages / sdk / src / helpers / neo.js View on Github external
// Imports
import * as axios from "axios";
import Neon, { api, rpc, tx, u, wallet } from "@cityofzion/neon-js";
import { queryHttpsProxy } from "@be-neo/neo-https-proxy";
const s2h = u.str2hexstring;
const sb = Neon.create.scriptBuilder;

const httpsProxy =
  "https://wt-eb8e8a5788a32c0054649520e12aca04-0.sandbox.auth0-extend.com/neo-https-proxy";

export const determineKey = key => {
  if (wallet.isNEP2(key)) return "NEP2";
  if (wallet.isWIF(key)) return "WIF";
  return false;
};

/**
 * Gets the value out of a key from a contract on the NEO Blockchain
 * @param {string} host Host endpoint
 * @param {string} contract Contract address
 * @param {string} key Key - to - search
 */
github be-neo / neoblog / packages / smart-contract-js-lib / src / blockchain / contract.js View on Github external
testInvoke: async (invoke) => {
    // Get local RPC 
    const client = await api.neonDB.getRPCEndpoint(localHost);
  
    // Create SC script
    const sb = Neon.create.scriptBuilder();
    sb.emitAppCall(invoke.scriptHash, invoke.operation.value, invoke.args, false);
    const script = sb.str;

    // Execute
    const response = await rpc.Query.invokeScript(script).execute(client);
    return response;
  },
  executeInvoke: async (account, invoke, gasCost, intents) => {
github be-neo / neoblog / packages / smart-contract-js-lib / src / blockchain / contract.js View on Github external
executeInvoke: async (account, invoke, gasCost, intents) => {
    // Get local RPC
    const client = await api.neonDB.getRPCEndpoint(localHost);

    // Create SC script
    const sb = Neon.create.scriptBuilder();
    sb.emitAppCall(invoke.scriptHash, invoke.operation.value, invoke.args, false);
    const script = sb.str;

    // Create TX
    const balances = await getBalance(account.address);
    const unsignedTx = tx.Transaction.createInvocationTx(balances, intents, script, gasCost, { version: 1 });
    const signedTx = tx.signTransaction(unsignedTx, account.privateKey);
    const hexTx = tx.serializeTransaction(signedTx);

    // Invoke
    return rpc.queryRPC(client, {
      method: 'sendrawtransaction',
      params: [hexTx],
      id: 1
    });
  },
github PacktPublishing / Foundations-of-Blockchain / Chapter07 / NEO / proof_of_ownership_app / interface / src / App.js View on Github external
queryAsset(assetID) {


        console.log(assetID.hexEncode());
        try {
            const props = {
                scriptHash: '60a7ed582c6885addf1f9bec7e413d01abe54f1a',
                operation: 'query',
                args: [assetID.hexEncode(),
                    ''
                ]
            };


            const Script = Neon.create.script(props);

            rpc.Query.invokeScript(Script).execute('http://139.59.25.30:30333').then((res) => {

                this.setState({fileOwner: scripthash_to_address(res.result.stack[0].value)});
            });
        } catch (err) {
            console.log(err);
        }
    }
github CityOfZion / neon-wallet / app / actions / pendingTransactionActions.js View on Github external
export const fetchTransactionInfo = async (
  transactions: PendingTransactions = {},
  address: string,
  net: string,
) => {
  if (Array.isArray(transactions[address]) && transactions[address].length) {
    let url = await getNode(net)
    if (isEmpty(url)) {
      url = await getRPCEndpoint(net)
    }
    const client = Neon.create.rpcClient(url)
    const pendingTransactionInfo = []

    for (const transaction of transactions[address]) {
      if (transaction) {
        const result = await client
          .getRawTransaction(transaction.hash, 1)
          .catch(async e => {
            console.error(
              e,
              `Error performing getRawTransaction for txid: ${
                transaction.hash
              }`,
            )
            if (e.message === INVALID_TX_ERROR_MESSAGE) {
              await pruneConfirmedOrStaleTransaction(address, transaction.hash)
            }
github NeoNextClub / neoline / src / app / core / services / neon.service.ts View on Github external
public importPrivateKey(privKey: string, key: string, name: string = null): Observable {
        const account = new wallet.Account(privKey);
        const w = Neon.create.wallet({ name: name || 'NEOLineUser' } as any);
        w.addAccount(account);
        const wif = w.accounts[0].WIF;
        w.encrypt(0, key);
        return from(w.accounts[0].encrypt(key)).pipe(map(() => {
            (w.accounts[0] as any).wif = wif;
            return w;
        }));
    }
    /**
github NeoNextClub / neoline / src / app / core / services / neon.service.ts View on Github external
wallet.decrypt(encKey, key).then((wif) => {
                const account = new wallet.Account(wallet.getPrivateKeyFromWIF(wif));
                const returnRes = Neon.create.wallet({ name: name || 'NEOLineUser' } as any);
                returnRes.addAccount(account);
                returnRes.encrypt(0, key);
                returnRes.accounts[0].encrypt(key).then(res => {
                    (returnRes.accounts[0] as any).wif = wif;
                    observer.next(returnRes);

                });
            }).catch((err) => {
                observer.error('import failed');