How to use the @cityofzion/neon-js.wallet.getScriptHashFromAddress 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 NeoNextClub / neoline / src / app / core / services / neon.service.ts View on Github external
public createTxForNEP5(from: string, to: string, scriptHash: string, amount: number, decimals: number): Transaction {
        const fromScript = wallet.getScriptHashFromAddress(from);
        const toScript = wallet.getScriptHashFromAddress(to);
        if (fromScript.length !== 40 || toScript.length !== 40) {
            throw new Error('target address error');
        }
        const newTx = new tx.InvocationTransaction();
        newTx.script = sc.createScript({
            scriptHash: scriptHash.startsWith('0x') && scriptHash.length === 42 ? scriptHash.substring(2) : scriptHash,
            operation: 'transfer',
            args: [
                u.reverseHex(fromScript),
                u.reverseHex(toScript),
                amount * Math.pow(10, decimals)
            ]
        }) + 'f1';
        newTx.addAttribute(tx.TxAttrUsage.Script, u.reverseHex(fromScript));
        const uniqTag = `from NEOLine at ${new Date().getTime()}`;
        newTx.addAttribute(tx.TxAttrUsage.Remark1, u.reverseHex(u.str2hexstring(uniqTag)));
github NeoNextClub / neoline / src / app / core / services / neon.service.ts View on Github external
public createTx(from: string, to: string, balances: UTXO[], amount: number, fee: number = 0): Transaction {

        const fromScript = wallet.getScriptHashFromAddress(from);
        const toScript = wallet.getScriptHashFromAddress(to);
        if (fromScript.length !== 40 || toScript.length !== 40) {
            throw new Error('target address error');
        }
        if (balances.length === 0) {
            throw new Error('no balance');
        }
        let assetId = balances[0].asset_id;
        if (assetId.startsWith('0x') && assetId.length === 66) {
            assetId = assetId.substring(2);
        }
        const newTx = new tx.ContractTransaction();

        newTx.addOutput({ assetId, value: new Fixed8(amount), scriptHash: toScript });
        let curr = 0.0;
        for (const item of balances) {
            curr += parseFloat(item.value) || 0;
github NeoNextClub / neoline / src / app / core / services / neon.service.ts View on Github external
public createTxForNEP5(from: string, to: string, scriptHash: string, amount: number, decimals: number): Transaction {
        const fromScript = wallet.getScriptHashFromAddress(from);
        const toScript = wallet.getScriptHashFromAddress(to);
        if (fromScript.length !== 40 || toScript.length !== 40) {
            throw new Error('target address error');
        }
        const newTx = new tx.InvocationTransaction();
        newTx.script = sc.createScript({
            scriptHash: scriptHash.startsWith('0x') && scriptHash.length === 42 ? scriptHash.substring(2) : scriptHash,
            operation: 'transfer',
            args: [
                u.reverseHex(fromScript),
                u.reverseHex(toScript),
                amount * Math.pow(10, decimals)
            ]
        }) + 'f1';
        newTx.addAttribute(tx.TxAttrUsage.Script, u.reverseHex(fromScript));
        const uniqTag = `from NEOLine at ${new Date().getTime()}`;
github CityOfZion / neon-wallet / app / modules / transactions.js View on Github external
const attachAttributesForEmptyTransaction = (config: api.apiConfig) => {
  config.tx.addAttribute(
    32,
    reverseHex(wallet.getScriptHashFromAddress(config.address)),
  )
  config.tx.addRemark(
    Date.now().toString() + ab2hexstring(wallet.generateRandomArray(4)),
  )
  return config
}