Example
window.addEventListener('NEOLine.NEO.EVENT.READY', () => {
const neoline = new NEOLine.Init();
neoline.getAccount()
.then(account => console.log(account))
});
getProvider
Returns information about the dAPI provider, including who this provider is, the version of their dAPI, and the NEP that the interface is compatible with.
Input Arguments
None
Success Response
Parameter | Description |
---|
name: string | The name of the wallet provider |
website: string | The website of the wallet provider |
version: string | The version of the dAPI that the the wallet supports |
compatibility: string[] | A list of all applicable NEPs which the wallet provider supports |
extra: object | This object can contain any attributes specific to the dapi provider, such as an app theme |
Error Response
Parameter | Description |
---|
type: string | The type of error which has occured |
description: string | A description of the error which has occured |
data: string | Any raw data associated with the error |
/* Example */
neoline.getProvider()
.then(provider => {
const {
name,
website,
version,
compatibility,
extra
} = provider;
console.log('Provider name: ' + name);
console.log('Provider website: ' + website);
console.log('Provider dAPI version: ' + version);
console.log('Provider dAPI compatibility: ' + JSON.stringify(compatibility));
console.log('Extra provider specific atributes: ' + JSON.stringify(compatibility));
})
.catch((error) => {
const {type, description, data} = error;
switch(type) {
case 'NO_PROVIDER':
console.log('No provider available.');
break;
case 'CONNECTION_DENIED':
console.log('The user rejected the request to connect with your dApp.');
break;
default:
// Not an expected error object. Just write the error to the console.
console.error(error);
break;
}
});
/* Example Response */
{
name: 'Awesome Wallet',
website: 'https://www.neoline.io/',
version: '1.0.0',
compatibility: [
'NEP-14',
'NEP-23',
'NEP-29'
],
extra: {
theme: 'Dark Mode',
currency: 'USD'
}
}
getNetworks
Returns the networks the wallet provider has available to connect to, along with the default network the wallet is currently set to.
Input Arguments
None
Success Response
Parameter | Description |
---|
networks: string[] | Array of network names the wallet provider has available for the dapp developer to connect to |
defaultNetwork: string | Network the wallet is currently set to |
Error Response
Parameter | Description |
---|
type: string | The type of error which has occured |
description: string | A description of the error which has occured |
data: string | Any raw data associated with the error |
/* Example */
neoline.getNetworks()
.then(result => {
const {
networks,
defaultNetwork
} = result;
console.log('Networks: ' + networks);
// eg. ["MainNet", "TestNet", "PrivateNet"]
console.log('Default network: ' + defaultNetwork);
// eg. "MainNet"
})
.catch((error) => {
const {type, description, data} = error;
switch(type) {
case 'NO_PROVIDER':
console.log('No provider available.');
break;
case 'CONNECTION_DENIED':
console.log('The user rejected the request to connect with your dApp');
break;
default:
// Not an expected error object. Just write the error to the console.
console.error(error);
break;
}
});
/* Example Response */
{
networks: ["MainNet", "TestNet"],
defaultNetwork: "TestNet"
}
getAccount
Return the Account that is currently connected to the dApp.
Input Arguments
None
Success Response
Parameter | Description |
---|
address: string | Address of the connected account |
label?: string | A label the users has set to identify their wallet |
isLedger: boolean | Whether the connected account is a ledger account |
Error Response
Parameter | Description |
---|
type: string | The type of error which has occured |
description: string | A description of the error which has occured |
data: string | Any raw data associated with the error |
/* Example */
neoline.getAccount()
.then(account => {
const {
address,
label,
isLedger
} = account;
console.log('Provider address: ' + address);
console.log('Provider account label (Optional): ' + label);
console.log('Provider account is ledger account: ' + isLedger);
})
.catch((error) => {
const {type, description, data} = error;
switch(type) {
case 'NO_PROVIDER':
console.log('No provider available.');
break;
case 'CONNECTION_DENIED':
console.log('The user rejected the request to connect with your dApp');
break;
default:
// Not an expected error object. Just write the error to the console.
console.error(error);
break;
}
});
/* Example Response */
{
address: 'AWSEU4BXpjGVdw9ajnFBXh8Rg8cgw9f3Zo',
label: 'NEOLine',
isLedger: false
}
getPublicKey
Return the public key of the Account that is currently connected to the dApp.
Input Arguments
None
Success Response
Parameter | Description |
---|
address: string | Address of the connected account |
publicKey: string | Public key of the connected account |
Error Response
Parameter | Description |
---|
type: string | The type of error which has occured |
description: string | A description of the error which has occured |
data: string | Any raw data associated with the error |
/* Example */
neoline.getPublicKey()
.then(publicKeyData => {
const {
address,
publicKey
} = publicKeyData;
console.log('Account address: ' + address);
console.log('Account public key: ' + publicKey);
})
.catch((error) => {
const {type, description, data} = error;
switch(type) {
case 'NO_PROVIDER':
console.log('No provider available.');
break;
case 'CONNECTION_DENIED':
console.log('The user rejected the request to connect with your dApp');
break;
default:
// Not an expected error object. Just write the error to the console.
console.error(error);
break;
}
});
/* Example Response */
{
address: 'AWSEU4BXpjGVdw9ajnFBXh8Rg8cgw9f3Zo',
publicKey: '03ba9524bd7479414be713c3a4f6f3ef35f90bb4b08f0f552211bf734c24415230'
}
getBalance
Return balance of a specific asset for the given account.
If the asset is omited from a request to MainNet, all asset and token balances will be returned.
Input Arguments
Parameter | Description |
---|
params: BalanceRequest | BalanceRequest[] | A list of Balance Request Objects, specifying which addresses, and which assets to query |
network?: string | Network to submit this request to. If omitted, will default to network the wallet is currently set to. |
BalanceRequest
Parameter | Description |
---|
address: string | Address to check balance(s) |
assets?: string | string[] | Asset ID or script hash to check balance |
fetchUTXO?: boolean | Fetches to UTXO data for NEO and/or GAS if attribute is 'true' |
Success Response
Parameter | Description |
---|
[address: string]: BalanceResponse[] | This key is the actual address of the query eg. "AWSEU4BXpjGVdw9ajnFBXh8Rg8cgw9f3Zo" |
BalanceResponse
Parameter | Description |
---|
assetID: string | ID of the given asset |
symbol: string | Symbol of the given asset |
amount: string | Double Value of the balance represented as a String |
unspent: UTXO[]? | If fetch utxo's was turned on then the utxo array will be returned for the native assets NEO and GAS |
UTXO
Parameter | Description |
---|
asset: string | Script hash of the native asset |
createdAtBlock: int | Block number where this utxo was created |
index: int | Output index of the UTXO relative to the txid in which it was created |
txid: string | The transaction id of this UTXO |
value: string | The double value of this UTXO represented as a String |
/* Example */
neoline.getBalance({
params: [
{
address: 'AUhp11NZfZEDKXWuSo5TPdGhnMx9wG2pdc',
assets: ['GAS','MCT', '0xc56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b', 'NEO']
},{
address: 'AWSEU4BXpjGVdw9ajnFBXh8Rg8cgw9f3Zo'
}
],
network: 'TestNet'
})
.then((results) => {
Object.keys(results).forEach(address => {
const balances = results[address];
balances.forEach(balance => {
const { assetID, symbol, amount } = balance
console.log('Address: ' + address);
console.log('Asset ID: ' + assetID);
console.log('Asset symbol: ' + symbol);
console.log('Amount: ' + amount);
});
});
})
.catch((error) => {
const {type, description, data} = error;
switch(type) {
case 'NO_PROVIDER':
console.log('No provider available.');
break;
case 'CONNECTION_DENIED':
console.log('The user rejected the request to connect with your dApp');
break;
default:
// Not an expected error object. Just write the error to the console.
console.error(error);
break;
}
});
/* Single asset balance request sample */
// input
{
params: {
address: 'AWSEU4BXpjGVdw9ajnFBXh8Rg8cgw9f3Zo',
assets: ['NEO']
},
network: 'TestNet'
}
// output
{
AWSEU4BXpjGVdw9ajnFBXh8Rg8cgw9f3Zo: [
{
assetID: '0xc56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b',
symbol: 'NEO',
amount: '6319'
}
],
}
/* Single account balances request sample */
// input
{
params: {
address: 'AWSEU4BXpjGVdw9ajnFBXh8Rg8cgw9f3Zo',
},
network: 'TestNet'
}
// output
{
AWSEU4BXpjGVdw9ajnFBXh8Rg8cgw9f3Zo: [
{
assetID: '0xc56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b',
symbol: 'NEO',
amount: '6319'
},
{
assetID: '0x602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7',
symbol: 'GAS',
amount: '2958.1094388'
}
]
}
/* Multiple account balances request sample */
// input
{
params: [
{
address: 'AUhp11NZfZEDKXWuSo5TPdGhnMx9wG2pdc'
},
{
address: 'AWSEU4BXpjGVdw9ajnFBXh8Rg8cgw9f3Zo',
asset: 'NEO'
}
],
network: 'TestNet'
}
// output
{
AUhp11NZfZEDKXWuSo5TPdGhnMx9wG2pdc: [
{
assetID: '0x602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7',
symbol: 'NEO',
amount: '1'
},
{
assetID: '0xc56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b',
symbol: 'GAS',
amount: '1'
},
],
AWSEU4BXpjGVdw9ajnFBXh8Rg8cgw9f3Zo: [
{
assetID: '0xc56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b',
symbol: 'NEO',
amount: '6319'
},
{
assetID: '0x602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7',
symbol: 'GAS',
amount: '2958.1094388'
}
]
}
getStorage
Reads the raw value in smart contract storage.
Input Arguments
Parameter | Description |
---|
scriptHash: string | Script hash of the smart contract to invoke a read on |
key: string | Key of the storage value to retrieve from the contract |
network?: string | Network to submit this request to. If omitted, will default to network the wallet is currently set to |
Success Response
Parameter | Description |
---|
result: string | The raw value that's stored in the contract |
Error Response
Parameter | Description |
---|
type: string | The type of error which has occured |
description: string | A description of the error which has occured |
data: string | Any raw data associated with the error |
/* Example */
neoline.getStorage({
scriptHash: '03febccf81ac85e3d795bc5cbd4e84e907812aa3',
key: 'Peter',
network: 'TestNet'
})
.then(result => {
const value = result;
console.log('Storage value: ' + value.result);
})
.catch((error) => {
const {type, description, data} = error;
switch(type) {
case 'NO_PROVIDER':
console.log('No provider available.');
break;
case 'CONNECTION_REFUSED':
console.log('Connection dApp not connected. Please call the "connect" function.');
break;
case 'RPC_ERROR':
console.log('There was an error when broadcasting this transaction to the network.');
break;
default:
// Not an expected error object. Just write the error to the console.
console.error(error);
break;
}
});
/* Example Response */
{
result: 'Lin'
}
invokeRead
Execute a contract invocation in read-only mode.
Input Arguments
Parameter | Description |
---|
scriptHash: string | Script hash of the smart contract to invoke a read on |
operation: string | Operation on the smart contract to call |
args: Argument[] | Any input arguments for the operation |
network?: string | Network to submit this request to. If omitted, will default to network the wallet is currently set to. |
Success Response
The wallet will return the direct response from the RPC node.
Parameter | Description |
---|
script: string | The script which was run |
state: string | Status of the executeion |
gas_consumed: string | Estimated amount of GAS to be used to execute the invocation. (Up to 10 free per transaction) |
stack: Argument[] | An array of response arguments |
Argument
Parameter | Description |
---|
type: 'String' | 'Boolean' | 'Hash160' | 'Hash256' | 'Integer' | 'ByteArray' | 'Array' | 'Address' | The type of the argument with you are using |
value: string | String representation of the argument which you are using |
Error Response
Parameter | Description |
---|
type: string | The type of error which has occured |
description: string | A description of the error which has occured |
data: string | Any raw data associated with the error |
/* Example */
neoline.invokeRead({
scriptHash: '0x96ef49bb4f67e25235a4cd4455d2f10779186ab2',
operation: 'balanceOf',
args: [
{
type: 'Address',
value: 'AY5xLg4RPZPcYoD1fW7j455PkAybbU2x42'
}
]
})
.then(result => {
console.log('Read invocation result: ' + JSON.stringify(result));
})
.catch((error) => {
const {type, description, data} = error;
switch(type) {
case 'NO_PROVIDER':
console.log('No provider available.');
break;
case 'CONNECTION_REFUSED':
console.log('Connection dApp not connected. Please call the "connect" function.');
break;
case 'RPC_ERROR':
console.log('There was an error when broadcasting this transaction to the network.');
break;
default:
// Not an expected error object. Just write the error to the console.
console.error(error);
break;
}
});
/* Example Response */
{
script: '14b2ed6ac7d282933322293e5a0c5c8bb12f9477f251c10962616c616e63654f6667b26a187907f1d25544cda43552e2674fbb49ef96',
state: 'HALT',
gas_consumed: '0.315',
stack: [
{
type: 'ByteArray',
value: '00902f5009'
}
]
}
verifyMessage
Returns whether the provided signature data matches the provided message and was signed by the account of the provided public key.
Input Arguments
Parameter | Description |
---|
message: string | Salt prefix + original message |
data: string | Signed message |
publicKey: string | Public key of account that signed message |
Success Response
Parameter | Description |
---|
result: boolean | Whether the provided signature matches the provided message and public key |
Error Response
Parameter | Description |
---|
type: string | The type of error which has occured |
description: string | A description of the error which has occured |
data: string | Any raw data associated with the error |
/* Example */
neoline.verifyMessage({
message: 'Hello world',
data: 'be506bf7e6851960bfe45968bf5dbbf79a9dc5dc63ee5b88629acfb288c435649c2766e977d4bc76253d8590bb3ca3d9b70efd71d6f7eebdf060dfa58c6601fd',
publicKey: '03ba9524bd7479414be713c3a4f6f3ef35f90bb4b08f0f552211bf734c24415230'
})
.then(result => {
console.log('Signature data matches provided message and public key: ' + JSON.stringify(result));
})
.catch((error) => {
const {type, description, data} = error;
switch(type) {
case 'NO_PROVIDER':
console.log('No provider available.');
break;
case 'CONNECTION_DENIED':
console.log('The user rejected the request to connect with your dApp');
break;
default:
// Not an expected error object. Just write the error to the console.
console.error(error);
break;
}
});
/* Example Response */
{
result: true
}
getBlock
Get information about a specific block.
Input Arguments
Parameter | Description |
---|
blockHeight: number | The height of the block you would like to get information about |
network?: string | Network to submit this request to. If omitted, will default to network the wallet is currently set to. If omitted, will default the network which the wallet is set to |
Success Response
The wallet will return the direct response from the RPC node.
Error Response
Parameter | Description |
---|
type: string | The type of error which has occured |
description: string | A description of the error which has occured |
data: string | Any raw data associated with the error |
/* Example */
neoline.getBlock({
blockHeight: 2619690,
network: 'TestNet'
})
.then(result => {
console.log('Block information: ' + JSON.stringify(result));
})
.catch((error) => {
const {type, description, data} = error;
switch(type) {
case 'NO_PROVIDER':
console.log('No provider available.');
break;
case 'RPC_ERROR':
console.log('There was an error when broadcasting this transaction to the network.');
break;
default:
// Not an expected error object. Just write the error to the console.
console.error(error);
break;
}
});
/* Example Response */
{
hash: "0xc1668a114ee680597196ed402a0e0507fd8348e6090a54250d7accfadbd74b6e",
size: 686,
version: 0,
previousblockhash: "0xbae289c94e17ae90022673186fd6e1e48b7dd7afb89319bff0e2832db06d16b3",
merkleroot: "0x07d70f7337d3869a7daa538425d78a47212fb8c6130d66d84ac48526853a4e51",
time: 1557376153,
index: 2619690,
nonce: "8efd62ebb85ee68b",
nextconsensus: "AWZo4qAxhT8fwKL93QATSjCYCgHmCY1XLB",
script: {
invocation: "402a1dab9e5593d1d7d2a22a36772d4541b8053d33f8b8474b7d5a20066c1bd821e051fc252ed16146930d55ecb17fbb74972fba4c4b27af81a707999ca1313dd2401520eba2dd3b54a74a798cbb716c484ba6f6f21218f099e3d622a0fbd15989f38f9b0b344daf9b89175055d3a92f49df65118e8598735d651bedd4f1811baeb140e6491c03f3057f404d2fe7db50e40e82ade405a9dc7fccd81f4ba0b499a4a29f8570d631b8d40c5995b17d9391fe9ff8c73f28a4e1eb922b7a1ce9d1a5dc0448402cfcdede54828875d45402120aa2d8f78c7bd40df5e5d3b1873fd7e4d03672ebd0904f90c90fa519c623968f55550ae55374de66dc0db9c9d865c593bb95be5640214db0cd3cea6f4ad866df4129d482b89583805d1bdb08ce8399881e70351778a3e4a4093cf69aa7b99b83347fbfd38d85ff45d6a78ca2ab8cacffbfbc8c2d16",
verification: "5521030ef96257401b803da5dd201233e2be828795672b775dd674d69df83f7aec1e36210327da12b5c40200e9f65569476bbff2218da4f32548ff43b6387ec1416a231ee821025bdf3f181f53e9696227843950deb72dcd374ded17c057159513c3d0abe20b64210266b588e350ab63b850e55dbfed0feeda44410a30966341b371014b803a15af0721026ce35b29147ad09e4afe4ec4a7319095f08198fa8babbe3c56e970b143528d222103c089d7122b840a4935234e82e26ae5efd0c2acb627239dc9f207311337b6f2c12103fd95a9cb3098e6447d0de9f76cc97fd5e36830f9c7044457c15a0e81316bf28f57ae"
},
tx: [
{
txid: "0x07d70f7337d3869a7daa538425d78a47212fb8c6130d66d84ac48526853a4e51",
size: 10,
type: "MinerTransaction",
version: 0,
attributes: [],
vin: [],
vout: [],
sys_fee: "0",
net_fee: "0",
scripts: [],
nonce: 3093227147
}
],
confirmations: 104111,
nextblockhash: "0x2c9d6a107b21e83e09dd1b89df344a726895147d410120c46996290692ba29aa"
}
getTransaction
Get information about a specific transaction.
Input Arguments
Parameter | Description |
---|
txid: string | The id of the transaction you would like to get information about |
network?: string | Network to submit this request to. If omitted, will default to network the wallet is currently set to. If omitted, will default the network which the wallet is set to |
Success Response
The wallet will return the direct response from the RPC node.
Error Response
Parameter | Description |
---|
type: string | The type of error which has occured |
description: string | A description of the error which has occured |
data: string | Any raw data associated with the error |
/* Example */
neoline.getTransaction({
txid: '0xfb3ecd6070e819187acaa307fb303fda7ae18577d98f948c4a4e13bce7ece474',
network: 'MainNet'
})
.then(result => {
console.log('Transaction details: ' + JSON.stringify(result));
})
.catch((error) => {
const {type, description, data} = error;
switch(type) {
case 'NO_PROVIDER':
console.log('No provider available.');
break;
case 'RPC_ERROR':
console.log('There was an error when broadcasting this transaction to the network.');
break;
default:
// Not an expected error object. Just write the error to the console.
console.error(error);
break;
}
});
/* Example Response */
{
txID: "0xfb3ecd6070e819187acaa307fb303fda7ae18577d98f948c4a4e13bce7ece474,
vin: [
{
address: "AZy5LGtAvwpyJMYq39xX4MsDzAL2B6pEZn",
assetID: "0xc56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b",
n: 0,
txid: "0xd7769e675a47bea100e1e9ea5e1723ec181d90b601884ffc4837844d4ca95103",
value: "4"
}
],
vout: [
{
address: "AZy5LGtAvwpyJMYq39xX4MsDzAL2B6pEZn",
assetID: "0xc56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b",
n: 0,
value: "4"
}
],
sys_fee: "0",
net_fee: "0",
blockIndex: 3840003,
blocktime: 1559707311
}
getApplicationLog
Get the application log for a given transaction.
Input Arguments
Parameter | Description |
---|
txid: string | The id of the transaction you would like to get the application logs for |
network?: string | Network to submit this request to. If omitted, will default to network the wallet is currently set to. If omitted, will default the network which the wallet is set to |
Success Response
The wallet will return the direct response from the RPC node.
Error Response
Parameter | Description |
---|
type: string | The type of error which has occured |
description: string | A description of the error which has occured |
data: string | Any raw data associated with the error |
/* Example */
neoline.getApplicationLog({
txid: '7e049fd7c253dabf38e4156df30c78b30d49f307196aa89b99a47d2330789bf2',
network: 'TestNet'
})
.then(result => {
console.log('Application log of transaction execution: ' + JSON.stringify(result));
})
.catch((error) => {
const {type, description, data} = error;
switch(type) {
case 'NO_PROVIDER':
console.log('No provider available.');
break;
case 'RPC_ERROR':
console.log('There was an error when broadcasting this transaction to the network.');
break;
default:
// Not an expected error object. Just write the error to the console.
console.error(error);
break;
}
});
/* Example Response */
{
txid: "0x7e049fd7c253dabf38e4156df30c78b30d49f307196aa89b99a47d2330789bf2",
executions: [
{
trigger: "Application",
contract: "0x72985e7f2cea98b89af54d8607bc6400814c4b45",
vmstate: "HALT, BREAK",
gas_consumed: "5.292",
stack: [],
notifications: [
{
contract: "0x849d095d07950b9e56d0c895ec48ec5100cfdff1",
state: {
type: "Array",
value: [
{
type: "ByteArray",
value: "7472616e73666572"
},
{
type: "ByteArray",
value: "296ac124021a71c449a9bad320c16429b08ad6ee"
},
{
type: "ByteArray",
value: "7869ef9732cdf6f6d54adaa5cae3b55a9396bceb"
},
{
type: "ByteArray",
value: "00e1f505"
}
]
}
},
{
contract: "0x849d095d07950b9e56d0c895ec48ec5100cfdff1",
state: {
type: "Array",
value: [
{
type: "ByteArray",
value: "7472616e73666572"
},
{
type: "ByteArray",
value: "296ac124021a71c449a9bad320c16429b08ad6ee"
},
{
type: "ByteArray",
value: "b1fdddf658ce5ff9f83e66ede2f333ecfcc0463e"
},
{
type: "ByteArray",
value: "00e1f505"
}
]
}
}
]
}
]
}
send
Invoke a transfer of a specified amount of a given asset from the connected account to another account.
Input Arguments
Parameter | Description |
---|
fromAddress: string | Address of the connected account to send the assets from |
toAddress: string | Address of the receiver of the assets to be sent |
asset: string | Asset script hash to be sent. Accepts asset symbol only for "MainNet" |
amount: string | The parsed amount of the asset to be sent |
remark?: string | Description of the transaction to be made |
fee?: string | The parsed amount of network fee (in GAS) to include with transaction |
network?: string | Network to submit this request to. If omitted, will default to network the wallet is currently set to |
broadcastOverride?: boolean | In the case that the dApp would like to be responsible for broadcasting the signed transaction rather than the wallet provider |
Success Response
In the case where the "broadcastOverride" input argument is not set, or set to false.
Parameter | Description |
---|
txid: string | The transaction ID of the send invocation |
nodeURL: string | The node which the transaction was broadcast to. Returned if transaction is broadcast by wallet provider |
In the case where the "broadcastOverride" input argument is set to True.
Parameter | Description |
---|
txid: string | The transaction ID of the send invocation |
signedTx: string | The serialized signed transaction. Only returned if the broadcastOverride input argument was set to True |
Error Response
Parameter | Description |
---|
type: string | The type of error which has occured |
description: string | A description of the error which has occured |
data: string | Any raw data associated with the error |
/* Example */
neoline.send({
fromAddress: 'AWSEU4BXpjGVdw9ajnFBXh8Rg8cgw9f3Zo',
toAddress: 'ALWNCcuQDoE287UWvYhRZYpPBDfswggbTX',
asset: 'NEO',
amount: '1',
remark: 'NEOLine',
fee: '0.0001',
network: 'TestNet',
broadcastOverride: false
})
.then(result => {
console.log('Send transaction success!');
console.log('Transaction ID: ' + result.txid);
console.log('RPC node URL: ' + result.nodeURL);
})
.catch((error) => {
const {type, description, data} = error;
switch(type) {
case 'NO_PROVIDER':
console.log('No provider available.');
break;
case 'RPC_ERROR':
console.log('There was an error when broadcasting this transaction to the network.');
break;
case 'MALFORMED_INPUT':
console.log('The receiver address provided is not valid.');
break;
case 'CANCELED':
console.log('The user has canceled this transaction.');
break;
case 'INSUFFICIENT_FUNDS':
console.log('The user has insufficient funds to execute this transaction.');
break;
default:
// Not an expected error object. Just write the error to the console.
console.error(error);
break;
}
});
/* Example Response */
{
txid: 'cb0cf81cdd75762545965038cea350c717a5d500bb40d4ca80fe45f416f564ac',
nodeURL: 'https://testnet.api.neoline.io'
}
invoke
Invoke allows for the generic execution of smart contracts on behalf of the user. It is reccommended to have a general understanding of the NEO blockchain, and to be able successfully use all other commands listed previously in this document before attempting a generic contract execution.
Input Arguments
Argument
Parameter | Description |
---|
type: 'String' | 'Boolean' | 'Hash160' | 'Hash256' | 'Integer' | 'ByteArray' | 'Array' | 'Address' | The type of the argument with you are using |
value: any | String representation of the argument which you are using |
TxHashAttribute
Parameter | Description |
---|
type: 'String' | 'Boolean' | 'Hash160' | 'Hash256' | 'Integer' | 'ByteArray' | 'Array' | 'Address' | The type of the argument with you are using |
value: any | String representation of the argument which you are using |
txAttrUsage: 'Hash1' | 'Hash2' | 'Hash3' | 'Hash4' | 'Hash5' | 'Hash6' | 'Hash7' | 'Hash8' | 'Hash9' | 'Hash10' | 'Hash11' | 'Hash12' | 'Hash13' | 'Hash14' | 'Hash15' | Attribute usage value |
AttachedAssets
Parameter | Description |
---|
NEO?: string | The amount of NEO to attach to the contract invocation |
GAS?: string | The amount of GAS to attach to the contract invocation |
AssetIntentOverrides
Parameter | Description |
---|
inputs: AssetInput[] | A list of UTXO inputs to use for this transaction |
outputs: AssetOutput[] | A list of UTXO outputs to use for this transaction |
AssetInput
Parameter | Description |
---|
txid: string | Transaction id to be used as input |
index: number | Index of the UTXO, can be found from transaction details |
AssetOutput
Parameter | Description |
---|
asset: string | Asset of the UTXO |
address: string | Address to receive the UTXO |
value: string | String representation of double or integer value to be used as output |
Success Response
In the case where the "broadcastOverride" input argument is not set, or set to false.
Parameter | Description |
---|
txid: string | The transaction ID of the invocation |
nodeURL: string | The node which the transaction was broadcast to. Returned if transaction is broadcast by wallet provider |
In the case where the "broadcastOverride" input argument is set to True.
Parameter | Description |
---|
txid: string | The transaction ID of the invocation |
signedTx: string | The serialized signed transaction. Only returned if the broadcastOverride input argument was set to True |
Error Response
Parameter | Description |
---|
type: string | The type of error which has occured |
description: string | A description of the error which has occured |
data: string | Any raw data associated with the error |
/* Example */
neoline.invoke({
scriptHash: 'af7c7328eee5a275a3bcaee2bf0cf662b5e739be',
operation: 'balanceOf',
args: [
{
type: 'Hash160',
value: '91b83e96f2a7c4fdf0c1688441ec61986c7cae26'
}
],
attachedAssets: {
NEO: '1',
GAS: '0.0001'
},
fee: '0.001',
network: 'TestNet',
broadcastOverride: false,
txHashAttributes: [
{
type: 'Boolean',
value: true,
txAttrUsage: 'Hash1'
}
]
})
.then(result => {
console.log('Invoke transaction success!');
console.log('Transaction ID: ' + result.txid);
console.log('RPC node URL: ' + result.nodeURL);
})
.catch((error) => {
const {type, description, data} = error;
switch(type) {
case 'NO_PROVIDER':
console.log('No provider available.');
break;
case 'RPC_ERROR':
console.log('There was an error when broadcasting this transaction to the network.');
break;
case 'CANCELED':
console.log('The user has canceled this transaction.');
break;
default:
// Not an expected error object. Just write the error to the console.
console.error(error);
break;
}
});
/* Example Response */
{
txid: 'd08c5f58675376832480f2959732caa2a0e024ad0304ed77c62146a9621124d6',
nodeUrl: 'https://testnet.api.neoline.io'
};
invokeMulti
Invoke Multi functions the same as Invoke, but accepts inputs to execute multiple invokes in the same transaction.
Input Arguments
Parameter | Description |
---|
fee?: string | If a fee is specified then the wallet SHOULD NOT override it, if a fee is not specified the wallet SHOULD allow the user to attach an optional fee |
network: string | Network alias to submit this request to. |
assetIntentOverrides?: AssetIntentOverrides | Used to specify the exact UTXO's to use for attached assets. If this is provided fee and attachedAssets will be ignored |
invokeArgs?: InvokeArguments[] | Array of contract invoke inputs |
broadcastOverride?: boolean | If this flag is set to True, the wallet provider will return the signed transaction rather than broadcasting to a node. |
txHashAttributes?: TxHashAttribute[] | Optional list of tx attribute hash values to be added |
InvokeArguments
Parameter | Description |
---|
scriptHash: string | The script hash of the contract that you wish to invoke |
operation: string | The operation on the smart contract that you wish to call. This can be fetched from the contract ABI |
args: Argument[] | A list of arguments necessary to perform on the operation you wish to call |
attachedAssets?: AttachedAssets[] | Describes the assets to attach with the smart contract, e.g. attaching assets to mint tokens during a token sale |
triggerContractVerification: bolean? | Adds the instruction to invoke the contract verifican trigger |
Argument
Parameter | Description |
---|
type: 'String' | 'Boolean' | 'Hash160' | 'Hash256' | 'Integer' | 'ByteArray' | 'Array' | 'Address' | The type of the argument with you are using |
value: any | String representation of the argument which you are using |
TxHashAttribute
Parameter | Description |
---|
type: 'String' | 'Boolean' | 'Hash160' | 'Hash256' | 'Integer' | 'ByteArray' | 'Array' | 'Address' | The type of the argument with you are using |
value: any | String representation of the argument which you are using |
txAttrUsage: 'Hash1' | 'Hash2' | 'Hash3' | 'Hash4' | 'Hash5' | 'Hash6' | 'Hash7' | 'Hash8' | 'Hash9' | 'Hash10' | 'Hash11' | 'Hash12' | 'Hash13' | 'Hash14' | 'Hash15' | Attribute usage value |
AssetIntentOverrides
Parameter | Description |
---|
inputs: AssetInput[] | A list of UTXO inputs to use for this transaction |
outputs: AssetOutput[] | A list of UTXO outputs to use for this transaction |
AssetInput
Parameter | Description |
---|
txid: string | Transaction id to be used as input |
index: number | Index of the UTXO, can be found from transaction details |
AssetOutput
Parameter | Description |
---|
asset: string | Asset of the UTXO |
address: string | Address to receive the UTXO |
value: string | String representation of double or integer value to be used as output |
Success Response
In the case where the "broadcastOverride" input argument is not set, or set to false.
Parameter | Description |
---|
txid: string | The transaction ID of the invocation |
nodeURL: string | The node which the transaction was broadcast to. Returned if transaction is broadcast by wallet provider |
In the case where the "broadcastOverride" input argument is set to True.
Parameter | Description |
---|
txid: string | The transaction ID of the invocation |
signedTx: string | The serialized signed transaction. Only returned if the broadcastOverride input argument was set to True |
Error Response
Parameter | Description |
---|
type: string | The type of error which has occured |
description: string | A description of the error which has occured |
data: string | Any raw data associated with the error |
/* Example */
neoline.invokeMulti({
invokeArgs: [
{
scriptHash: "808f0823a811cdb7d80af3509e900cc2f594ceb1",
operation: "transfer",
args: [
{
"type": "Address",
"value": "AWSEU4BXpjGVdw9ajnFBXh8Rg8cgw9f3Zo"
},
{
"type": "Address",
"value": "AY69kajrRx1Qk29AeLxvkXHYf2h3pQw9yK"
},
{
"type": "Integer",
"value": "100000000"
}
],
attachedAssets: {
NEO: '1',
GAS: '0.0001'
},
},
{
scriptHash: "808f0823a811cdb7d80af3509e900cc2f594ceb1",
operation: "transfer",
args: [
{
"type": "Address",
"value": "AWSEU4BXpjGVdw9ajnFBXh8Rg8cgw9f3Zo"
},
{
"type": "Address",
"value": "AY69kajrRx1Qk29AeLxvkXHYf2h3pQw9yK"
},
{
"type": "Integer",
"value": "300000000"
}
],
attachedAssets: {
NEO: '2',
GAS: '0.01'
},
}
],
fee: '0.01',
network: 'TestNet',
broadcastOverride: false,
txHashAttributes: [
{
type: 'Boolean',
value: true,
txAttrUsage: 'Hash1'
}
]
})
.then(({txid, nodeURL}: InvokeOutput) => {
console.log('Invoke transaction success!');
console.log('Transaction ID: ' + txid);
console.log('RPC node URL: ' + nodeURL);
})
.catch((error) => {
const {type, description, data} = error;
switch(type) {
case NO_PROVIDER:
console.log('No provider available.');
break;
case RPC_ERROR:
console.log('There was an error when broadcasting this transaction to the network.');
break;
case CANCELED:
console.log('The user has canceled this transaction.');
break;
default:
// Not an expected error object. Just write the error to the console.
console.error(error);
break;
}
});
/* Example Response */
{
txid: "8979389ac095c37c43fa6922ae3f1180e33082394b43108b82cb0ca37d900541",
nodeURL: "https://testnet.api.neoline.io"
};
signMessage
Signs a provided messaged with an account selected by user. A randomized salt prefix is added to the input string before it is signed, and it is encased in a non-executable transaction before signed. This ensures compatibility with Ledger devices.
Input Arguments
Parameter | Description |
---|
message: string | The message to sign |
isJsonObject?: boolean | Whether message is a json object |
Success Response
Parameter | Description |
---|
publicKey: string | Public key of account that signed message |
data: string | Original message signed |
salt: string | Salt added to original message as prefix, before signing |
message: string | Signed message |
Error Response
Parameter | Description |
---|
type: string | The type of error which has occured |
description: string | A description of the error which has occured |
data: string | Any raw data associated with the error |
/* Example */
neoline.signMessage({
message: 'Hello world'
})
.then(signedMessage => {
const {
publicKey,
message,
salt,
data
} = signedMessage;
console.log('Public key used to sign:', publicKey);
console.log('Original message:', message);
console.log('Salt added to message:', salt);
console.log('Signed data:', data);
})
.catch((error) => {
const {type, description, data} = error;
switch(type) {
case UNKNOWN_ERROR:
console.log(description);
break;
default:
// Not an expected error object. Just write the error to the console.
console.error(error);
break;
}
});
/* Example Response */
{
publicKey: '"03ba9524bd7479414be713c3a4f6f3ef35f90bb4b08f0f552211bf734c24415230"',
data: '"be506bf7e6851960bfe45968bf5dbbf79a9dc5dc63ee5b88629acfb288c435649c2766e977d4bc76253d8590bb3ca3d9b70efd71d6f7eebdf060dfa58c6601fd"',
salt: '',
message: 'Hello world'
}
deploy
Will deploy a compiled smart contract to the blockchain with the provided input parameters. The GAS cost for deploying the contract will be calculated by the provider, and displayed to the user upon tx acceptance or rejection.
Input Arguments
Parameter | Description |
---|
network?: string | Network to submit this request to. If omitted, will default to network the wallet is currently set to |
name: string | The name of the contract to be deployed |
version: string | The version of the contract to be deployed |
author: string | The author of the contract to be deployed |
email: string | The email of the contract to be deployed |
description: string | The description of the contract to be deployed |
needsStorage?: boolean | Whether or not the contract will use storage |
dynamicInvoke?: boolean | Whether or not the contract will be performing dynamic invocations of other smart contracts |
isPayable?: boolean | Whether or not the contract will be able to accept native assets |
parameterList: string | The list of input argument types for the Main function on the contract. https://docs.neo.org/en-us/sc/Parameter.html |
returnType: string | The list of output returnType argument types. https://docs.neo.org/en-us/sc/Parameter.html |
code: string | The hex of the compiled smart contract avm |
netowrkFee: number | The network fee to execute the transaction, in addition to the deploy fee which will be added automatically |
broadcastOverride?: boolean | In the case that the dApp would like to be responsible for broadcasting the signed transaction rather than the wallet provider |
Success Response
In the case where the "broadcastOverride" input argument is not set, or set to false.
Parameter | Description |
---|
txid: string | The transaction ID of the invocation |
nodeURL: string | The node which the transaction was broadcast to. Returned if transaction is broadcast by wallet |
In the case where the "broadcastOverride" input argument is set to True.
Parameter | Description |
---|
txid: string | The transaction ID of the invocation |
signedTx: string | The serialized signed transaction. Only returned if the broadcastOverride input argument was set to True |
Error Response
Parameter | Description |
---|
type: string | The type of error which has occured |
description: string | A description of the error which has occured |
data: string | Any raw data associated with the error |
/* Example */
neoline.deploy({
network: 'TestNet',
name: 'Hello world!',
version: 'v1.0.0',
author: 'NEOLine',
email: 'info@neoline.network',
description: 'My first contract.',
needsStorage: true,
dynamicInvoke: false,
isPayable: false,
parameterList: '0710',
returnType: '05',
code: '53c56b0d57616b652075702c204e454f21680f4e656f2e52756e74696d652e4c6f6761006c7566',
networkFee: '0.001'
})
.then(({txid, nodeURL}: InvokeOutput) => {
console.log('Deploy transaction success!');
console.log('Transaction ID: ' + txid);
console.log('RPC node URL: ' + nodeURL);
})
.catch((error) => {
const {type, description, data} = error;
switch(type) {
case UNKNOWN_ERROR:
console.log(description);
break;
default:
// Not an expected error object. Just write the error to the console.
console.error(error);
break;
}
});
/* Example Response */
{
txid: '629b5f35e42aa6b65cd97ae3a95f89547596f4e2783c8778428c7f32df07918e',
nodeUrl: 'https://testnet.api.neoline.io'
};
switchWalletNetwork
Allows NeoLine applications ('dapps') to request that the wallet switches its active Neo network.
Parameter | Description |
---|
chainId:number | Switch the chainId of the network |
Chain IDs Type
These are the IDs of the Neo chain supported by NeoLine.
chainId | Description |
---|
1 | ChainId 1 is the Neo2 MainNet |
2 | ChainId 2 is the Neo2 TestNet |
3 | ChainId 3 is the N3 MainNet |
6 | ChainId 6 is the N3 TestNet (Currently only N3 TestNet) |
0 | ChainId 0 is the N3 Private Network |
Success Response
Null
Error Response
Parameter | Description |
---|
type: string | The type of error which has occured |
description: string | A description of the error which has occured |
data: string | Any raw data associated with the error |
/* Example */
neoline.switchWalletNetwork({
chainId: 3
})
.then(() => {})
.catch((error) => {
const {type, description, data} = error;
switch(type) {
case UNKNOWN_ERROR:
console.log(description);
break;
default:
// Not an expected error object. Just write the error to the console.
console.error(error);
break;
}
});
/* Example Response */
null
switchWalletAccount
Allows NeoLine applications ('dapps') to request that the wallet switches its active account.
Input Arguments
None
Success Response
Parameter | Description |
---|
address: string | Address of the connected account |
label?: string | A label the users has set to identify their wallet |
isLedger: boolean | Whether the connected account is a ledger account |
Error Response
Parameter | Description |
---|
type: string | The type of error which has occured |
description: string | A description of the error which has occured |
data: string | Any raw data associated with the error |
/* Example */
neoline.switchWalletAccount()
.then(account => {
const {
address,
label,
isLedger
} = account;
console.log('Provider address: ' + address);
console.log('Provider account label (Optional): ' + label);
console.log('Provider account is ledger account: ' + isLedger);
})
.catch((error) => {
const {type, description, data} = error;
switch(type) {
case UNKNOWN_ERROR:
console.log(description);
break;
default:
// Not an expected error object. Just write the error to the console.
console.error(error);
break;
}
});
/* Example Response */
{
address: 'AWSEU4BXpjGVdw9ajnFBXh8Rg8cgw9f3Zo',
label: 'NEOLine',
isLedger: false
}
READY
On a READY event, the callback will fire with a single argument with information about the wallet provider. At any time a READY event listener is added, it will immidiately be called if the provider is already in a ready state. This provides a single flow for dapp developers since this listener should start any and all interactions with the dapi protocol.
Parameter | Description |
---|
name: string | The name of the wallet provider |
website: string | The website of the wallet provider |
version: string | The version of the dAPI that the the wallet supports |
compatibility: string[] | A list of all applicable NEPs which the wallet provider supports |
extra: object | Provider specific attributes |
/* Example */
window.addEventListener('NEOLine.NEO.EVENT.READY', () => {
console.log('dAPI common method loading is complete.');
});
ACCOUNT_CHANGED
On a ACCOUNT_CHANGED event, the callback will fire with a single argument of the new account. This occurs when an account is already connected to the dapp, and the user has changed the connected account from the dapi provider side.
Parameter | Description |
---|
address: string | Address of the connected account |
label: string | A label the users has set to identify their wallet |
/* Example */
neoline.addEventListener(neoline.EVENT.ACCOUNT_CHANGED, (result) => {
console.log('account changed:', result);
});
/* Another */
window.addEventListener('NEOLine.NEO.EVENT.ACCOUNT_CHANGED', (result) => {
console.log('account changed:', result.detail);
});
CONNECTED
On a CONNECTED event, the user has approved the connection of the dapp with one of their accounts. This will fire the first time any of one of the following methods are called from the dapp: getAccount
, invoke
, send
.
Parameter | Description |
---|
address: string | Address of the new account |
label: string | A label the users has set to identify their wallet |
/* Example */
neoline.addEventListener(neoline.EVENT.CONNECTED, (result) => {
console.log('connected account:', result);
});
/* Another */
window.addEventListener('NEOLine.NEO.EVENT.CONNECTED', (result) => {
console.log('connected account:', result.detail);
});
DISCONNECTED
On a DISCONNECTED event, the account connected to the dapp via the dapi provider has been disconnected (logged out).
/* Example */
neoline.addEventListener(neoline.EVENT.DISCONNECTED, () => {
console.log('dAPI public method loading is complete.');
});
/* Another */
window.addEventListener('NEOLine.NEO.EVENT.DISCONNECTED', () => {
console.log('dAPI public method loading is complete.');
});
NETWORK_CHANGED
On a NETWORK_CHANGED event, the user has changed the network their provider wallet is connected to. The event will return the updated network details.
Parameter | Description |
---|
networks: string[] | A list of all networks which this wallet provider allows access to |
defaultNetwork: string | Network the wallet is currently set to |
/* Example */
neoline.addEventListener(neoline.EVENT.NETWORK_CHANGED, (result) => {
console.log('network:', result);
});
/* Another */
window.addEventListener('NEOLine.NEO.EVENT.NETWORK_CHANGED', (result) => {
console.log('network:', result.detail);
});
BLOCK_HEIGHT_CHANGED
On a BLOCK_HEIGHT_CHANGED event, the block has advanced to the next.
Parameter | Description |
---|
network?: string | Network of the block which changed |
blockHeight: number | Height of the new block |
blockTime: number | Timestamp of the new block |
blockHash: string | Hash of the new block |
tx: string[] | List of transaction ids executed in the new block |
/* Example */
neoline.addEventListener(neoline.EVENT.BLOCK_HEIGHT_CHANGED, (result) => {
console.log('block height:', result);
});
/* Another */
window.addEventListener('NEOLine.NEO.EVENT.BLOCK_HEIGHT_CHANGED', (result) => {
console.log('block height:', result.detail);
});
TRANSACTION_CONFIRMED
On a TRANSACTION_CONFIRMED event, a previously broadcast transaction via the dapi has been confirmed by the blockchain.
Parameter | Description |
---|
txid: string | Transaction id which was confirmed on chain |
blockHeight: number | Height of the new block |
blockTime: number | Timestamp of the new block |
/* Example */
neoline.addEventListener(neoline.EVENT.TRANSACTION_CONFIRMED, (result) => {
console.log('Transaction confirmation detail:', result);
});
/* Another */
window.addEventListener('NEOLine.NEO.EVENT.TRANSACTION_CONFIRMED', (result) => {
console.log('Transaction confirmation detail:', result.detail);
});
addEventListener
Method is used to add a callback method to be triggered on a specified event.
/* Example */
const fn = (data) => {
console.log(`Connected Account: ${data.address}`);
}
neoline.addEventListener(neoline.EVENT.ACCOUNT_CHANGED, fn);
/* Another */
const fn = (data) => {
console.log(`Connected Account: ${data.detail.address}`);
}
window.addEventListener('NEOLine.NEO.EVENT.ACCOUNT_CHANGED', fn) ;
removeEventListener
Method is to remove existing callback event listeners.
/* Example */
neoline.removeEventListener(neoline.EVENT.ACCOUNT_CHANGED, fn);
/* Another */
window.removeEventListener('NEOLine.NEO.EVENT.ACCOUNT_CHANGED', fn);
Errors
The NEO dAPI will provide these basic errors. It is up to the wallet provider to provide additional information if they choose:
Error Type | Meaning |
---|
NO_PROVIDER | Thrown when there is no interface capable of interacting with NEO blockchain |
CONNECTION_DENIED | Thrown when API provider refuses to execute a transaction (e.g. trying to execute a transaction on an unavialable network) |
RPC_ERROR | Thrown when a command relying on RPC connection to a network node fails |
MALFORMED_INPUT | Thrown when an input such as the address is not a valid NEO address |
CANCELED | Thrown when a user cancels, or refuses the dapps request |
INSUFFICIENT_FUNDS | Thrown when the action does not have a sufficient balance |
FAIL | The request failed |