Example
If you need to call the N3 dAPI monitoring method, you need to initialize NEOLine after initializing NEOLineN3, please refer to the example on the right.
let neoline;
let neolineN3;
function initDapi() {
const initCommonDapi = new Promise((resolve, reject) => {
window.addEventListener('NEOLine.NEO.EVENT.READY', () => {
neoline = new NEOLine.Init();
if (neoline) {
resolve(neoline);
} else {
reject('common dAPI method failed to load.');
}
});
});
const initN3Dapi = new Promise((resolve, reject) => {
window.addEventListener('NEOLine.N3.EVENT.READY', () => {
neolineN3 = new NEOLineN3.Init();
if (neolineN3) {
resolve(neolineN3);
} else {
reject('N3 dAPI method failed to load.');
}
});
});
initCommonDapi.then(() => {
console.log('The common dAPI method is loaded.');
return initN3Dapi;
}).then(() => {
console.log('The N3 dAPI method is loaded.');
}).catch((err) => {
console.log(err);
})
};
initDapi();
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 */
neolineN3.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: [],
extra: {}
}
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[] | A list of Balance Request Objects, specifying which addresses, and which assets to query |
BalanceRequest
Parameter | Description |
---|
address: string | Address to check balance(s) |
contracts: string[] | contracts is a list of contract hash |
Success Response
Parameter | Description |
---|
[address: string]: BalanceResponse[] | This key is the actual address of the query eg. "NdJqYNVK99srFABQDLPdrpz2By1RX1sLvr" |
BalanceResponse
Parameter | Description |
---|
contract: string | contract of the given hash |
symbol: string | Symbol of the given contract |
amount: string | Double Value of the balance represented as a String |
/* Example */
neolineN3.getBalance()
.then((results) => {
Object.keys(results).forEach(address => {
const balances = results[address];
balances.forEach(balance => {
const { contract, symbol, amount } = balance
console.log('Address: ' + address);
console.log('contract: ' + contract);
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;
}
});
// output
[
{
"symbol": "NEO",
"amount": "5000000",
"contract": "0xef4073a0f2b305a38ec4050e4d3d28bc40ea63f5"
},
{
"symbol": "GAS",
"amount": "10063.4476161",
"contract": "0xd2a4cff31913016155e38e474a2c06d08be276cf"
}
]
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 |
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 */
neolineN3.getStorage({
scriptHash: '006b26dd0d2aa076b11082847a094772450f05af',
key: 'token0',
})
.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: 'wYCMqLCTIUiax57E8Zd/O9xN3l8='
}
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 |
signers: Signers[] | Sender and the effective scope of signature |
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. The type is an array, please see the example for the value. |
value: string | String representation of the argument which you are using |
Signer
Parameter | Description |
---|
account: string | scriptHash of the address |
scopes: number | Effective range of the signature |
allowedContracts?: Array | Contracts of the signature can take effect, if scopes is CustomContracts |
allowedGroups?: Array | Pubkeys of the signature can take effect, if scopes is CustomGroups |
rules?: WitnessRule[] | Custom rules for witness to adhere by, if scopes is WitnessRules |
Scopes
Field | Description |
---|
0 | Only transactions are signed and no contracts are allowed to use this signature. |
1 | It only applies to the chain call entry. That is, if the user invokes contract A, and then contract A calls contract B, only contract A can use the signature. It is recommended as the default value for the wallet. |
16 | Custom contract. The signature can be used in the specified contract. It can be used in conjunction with CalledByEntry. |
32 | Custom contract groups that can be used in a specified contract group. It can be used in conjunction with CalledByEntry. |
64 | Indicates that the current context must satisfy the specified rules. |
128 | Global. The risk is extremely high because the contract may transfer all assets in the address. Only choose it when the contract is extremely trusted. |
WitnessRule
Parameter | Description |
---|
action: 'Deny' | 'Allow' | Represents the action of a WitnessRule. |
condition: WitnessCondition | Represents the condition of a WitnessRule. |
WitnessCondition
Field | Description |
---|
BooleanWitnessCondition | Indicates that the condition will always be met or not met. |
AndWitnessCondition | Indicates that all conditions must be met. |
NotWitnessCondition | Reverse another condition. |
OrWitnessCondition | Indicates that any of the conditions meets. |
ScriptHashWitnessCondition | Indicates that the condition is met when the current context has the specified script hash. |
GroupWitnessCondition | Indicates that the condition is met when the current context has the specified group. |
CalledByEntryWitnessCondition | Indicates that the condition is met when the current context is the entry point or is called by the entry point. |
CalledByContractWitnessCondition | Indicates that the condition is met when the current context is called by the specified contract. |
CalledByGroupWitnessCondition | Indicates that the condition is met when the current context is called by the specified group. |
BooleanWitnessCondition
Parameter | Description |
---|
type: 'Boolean' | The type of the BooleanWitnessCondition. |
expression: boolean | The expression of the BooleanWitnessCondition. |
AndWitnessCondition
Parameter | Description |
---|
type: 'And' | The type of the AndWitnessCondition. |
expressions: WitnessCondition[] | The expressions of the AndWitnessCondition. |
NotWitnessCondition
Parameter | Description |
---|
type: 'Not' | The type of the NotWitnessCondition. |
expression: WitnessCondition | The expression of the NotWitnessCondition. |
OrWitnessCondition
Parameter | Description |
---|
type: 'Or' | The type of the OrWitnessCondition. |
expressions: WitnessCondition[] | The expressions of the OrWitnessCondition. |
ScriptHashWitnessCondition
Parameter | Description |
---|
type: 'ScriptHash' | The type of the ScriptHashWitnessCondition. |
hash: string | The hash of the ScriptHashWitnessCondition. |
GroupWitnessCondition
Parameter | Description |
---|
type: 'Group' | The type of the GroupWitnessCondition. |
group: string | The group of the GroupWitnessCondition. |
CalledByEntryWitnessCondition
Parameter | Description |
---|
type: 'CalledByEntry' | The type of the CalledByEntryWitnessCondition. |
CalledByContractWitnessCondition
Parameter | Description |
---|
type: 'CalledByContract' | The type of the CalledByContractWitnessCondition. |
hash: string | The hash of the CalledByContractWitnessCondition. |
CalledByGroupWitnessCondition
Parameter | Description |
---|
type: 'CalledByGroup' | The type of the CalledByGroupWitnessCondition. |
group: string | The group of the CalledByGroupWitnessCondition. |
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 */
neolineN3.invokeRead({
scriptHash: 'd2a4cff31913016155e38e474a2c06d08be276cf',
operation: 'transfer',
args: [
{
"type": "Hash160",
"value": "0xebae4ab3f21765e5f604dfdd590fdf142cfb89fa"
},
{
"type": "Hash160",
"value": "0xebae4ab3f21765e5f604dfdd590fdf142cfb89fa"
},
{
"type": "Integer",
"value": "10000"
},
{
"type": "String",
"value": ""
}
],
signers: [
{
account: "2cab903ff032ac693f8514581665be534beac39f",
scopes: 1
}
],
})
.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: "DAABECcMFPqJ+ywU3w9Z3d8E9uVlF/KzSq7rDBT6ifssFN8PWd3fBPblZRfys0qu6xTAHwwIdHJhbnNmZXIMFM924ovQBixKR47jVWEBExnzz6TSQWJ9W1I=",
state:"HALT",
stack:[
{
type:"Boolean",
value:false
}
]
}
/* Example, Type is array */
args: [
{
type: "Array",
value: [
{
type: "String",
value: "0x576f726c64"
}, {
type: "String",
value: "0x576f726c64"
}
]
}
]
invokeReadMulti
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 |
invokeReadArgs: Argument[] | Any input arguments for the operation |
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 */
neolineN3.invokeReadMulti({
invokeReadArgs: [
{
scriptHash: "d2a4cff31913016155e38e474a2c06d08be276cf",
operation: "balanceOf",
args: [
{
type: "Address",
value: "NaUjKgf5vMuFt7Ffgfffcpc41uH3adx1jq",
}
]
},
{
scriptHash: "d2a4cff31913016155e38e474a2c06d08be276cf",
operation: "balanceOf",
args: [
{
type: "Address",
value: "NaUjKgf5vMuFt7Ffgfffcpc41uH3adx1jq",
}
]
}
],
signers: [
{
account: "2cab903ff032ac693f8514581665be534beac39f",
scopes: 1
}
]
}).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": "DBRHsV1d1v6Pnc51X7CYvP4eBbMIAxHAHwwJYmFsYW5jZU9mDBTPduKL0AYsSkeO41VhARMZ88+k0kFifVtS",
"state": "HALT",
"stack": [
{
"type": "Integer",
"value": "5293314113"
}
]
},
{
"script": "DBRHsV1d1v6Pnc51X7CYvP4eBbMIAxHAHwwJYmFsYW5jZU9mDBTPduKL0AYsSkeO41VhARMZ88+k0kFifVtS",
"state": "HALT",
"stack": [
{
"type": "Integer",
"value": "5293314113"
}
]
}
]
Returns whether the provided signature data matches the provided message and was signed by the account of the provided public key. For the complete verification process, please go to Testbed.
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 */
neolineN3.verifyMessage({
message: '42e038cec78bed9f1e503c4b23254b23Hello 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
}
verifyMessageV2 Testbed
Returns whether the provided signature data matches the provided message and was signed by the account of the provided public key. For the complete verification process, please go to Testbed.
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 */
neolineN3.verifyMessageV2({
message: '543e66d70a56506f0a69aff35f25f794Hello world',
data: '4fef4abd1ced91577c89eac7909b89ec2aa3d073178c51c3074b7bc5551093b00bf274f35f8166931dc90cbd88346729e86e0bf1c3014fa3587cc167f0cafd4c',
publicKey: '023e72b8b5a20c00dac7ac01ecd72354a2d7d64620d6615524bb18b9f5a6ca8ef4'
})
.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 |
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 */
neolineN3.getBlock({
blockHeight: 190,
})
.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": "0x70635ef3ab897294bcde97255ea1197f99d7d6c587f720430b78743d25f8b313",
"size": 689,
"version": 0,
"previousblockhash": "0xb2462644577fdc9302abfe3517d07cbb9e7d51354872257901ba3ab1c2f4ead6",
"merkleroot": "0x0000000000000000000000000000000000000000000000000000000000000000",
"time": 1616899442433,
"index": 190,
"primary": 6,
"nextconsensus": "NNjNWMEgRw9bnvg7RkjSB9FZfzXUXfqovh",
"witnesses": [
{
"invocation": "DEAl4+T5RivIUYtCcMDCw/W2G3VvNRWRD8iWv447hmeuUo1XxyqHvC9wFYWWu1ar2Qr6sO36mHlJI6W1lmTol7sSDEDZmjj1k/TGr2f4Ii3IUZyxzroJ6/6pBBZhgafUYFPX1zMJBXYPqpGP7Ppqw8n/jUOgYq7u0XAzzbCco7qT4/1mDECVyDVhe2EwxXpvp9bUGgVH9SOoXub7fsN7zB+7kiEXpSNU0Fp7kn4uIsLE8PlDfEyKktFAMPBEzw1+WJZr/MgmDEB0RS82LHuKwwHmQ24QuRfk6YuFs3bLXFdtvL0BrlwpYrtOEDr6hitybvJ6X2NBiRf5+O88MO/ph3KJwIc7deN4DEDOdD1Ks34NSPHqd/7tNt/kqjIokEkRfxSCoXoBdbuSwQBQr5G6q/a9MpE9WQ+td0+XCsOKPi82QzxXo/TLJnoJ",
"verification": "FQwhAwCbdUDhDyVi5f2PrJ6uwlFmpYsm5BI0j/WoaSe/rCKiDCECPpsy6om5TQZuZJsST9UOOW7pE2no4qauGxHBcNAiJW0MIQNAjc1BY5b2R4OsWH6h4Vk8V9n+qIDIpqGSDpKiWUd4BgwhAqeDS+mzLimB0VfLW706y0LP0R6lw7ECJNekTpjFkQ8bDCECuixw9ZlvNXpDGYcFhZ+uLP6hPhFyligAdys9WIqdSr0MIQPOExCxK5ItwD/pBcxnN+YrOEwO+j8VZouFPQPAFoJb8AwhAuhZNE7zW7H/65wlUytAKMW4d9uGGtsIYcng7dPIxnyLF0F7zmyl"
}
],
"tx": [],
"confirmations": 207480,
"nextblockhash": "0xb95e56772d16a02f54c9f9cf071bdb60c92d4b6dc0f0eddd7c8388d5649f112b"
}
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 |
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 */
neolineN3.getTransaction({
txid: '0xe5a5fdacad0ba4e8d34d2fa0638357adb0f05e7fc902ec150739616320870f50'
})
.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 */
{
"hash": "0xc156988547570d1c852d9a56324b2e09d89077ff0aee2070d0b470332ae1e083",
"size": 244,
"sys_fee": "0.0997775",
"net_fee": "0.0124379",
"block_index": 103879,
"block_time": 1618238381713,
"version": 0,
"transfers": [
{
"hash": "0xc156988547570d1c852d9a56324b2e09d89077ff0aee2070d0b470332ae1e083",
"src": "tx",
"contract": "0xd2a4cff31913016155e38e474a2c06d08be276cf",
"from": "",
"to": "NaUjKgf5vMuFt7Ffgfffcpc41uH3adx1jq",
"amount": "0.00004914"
},
{
"hash": "0xc156988547570d1c852d9a56324b2e09d89077ff0aee2070d0b470332ae1e083",
"src": "tx",
"contract": "0xef4073a0f2b305a38ec4050e4d3d28bc40ea63f5",
"from": "NaUjKgf5vMuFt7Ffgfffcpc41uH3adx1jq",
"to": "NaUjKgf5vMuFt7Ffgfffcpc41uH3adx1jq",
"amount": "1"
}
]
}
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 |
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 */
neolineN3.getApplicationLog({
txid: '0xe5a5fdacad0ba4e8d34d2fa0638357adb0f05e7fc902ec150739616320870f50',
})
.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 */
{
"blockhash": "0xa8184d1fb08199ca8926f992b6253962c4a8047f7d4cfc5ac420e346fa761b03",
"executions": [
{
"trigger": "OnPersist",
"vmstate": "HALT",
"gasconsumed": "0",
"stack": [],
"notifications": []
},
{
"trigger": "PostPersist",
"vmstate": "HALT",
"gasconsumed": "0",
"stack": [],
"notifications": [
{
"contract": "0xd2a4cff31913016155e38e474a2c06d08be276cf",
"eventname": "Transfer",
"state": {
"type": "Array",
"value": [
{
"type": "Any"
},
{
"type": "ByteString",
"value": "iQwOXsDt//2me0sNlRpUdBcVOg4="
},
{
"type": "Integer",
"value": "50000000"
}
]
}
}
]
}
]
}
pickAddress
Returns the NEO N3 account selected by the user.
Input Arguments
None
Success Response
Parameter | Description |
---|
label: string | A label the users has set to identify their wallet |
address: string | The NEO N3 account address selected by the user |
/* Example */
neolineN3.pickAddress()
.then(result => {
const { label, address } = result;
console.log('label:' + label);
console.log('address' + address);
})
.catch((error) => {
const {type, description, data} = error;
switch(type) {
case 'NO_PROVIDER':
console.log('No provider available.');
break;
case 'CANCELED':
console.log('The user cancels, or refuses the dapps request');
break;
default:
// Not an expected error object. Just write the error to the console.
console.error(error);
break;
}
});
/* Example Response */
{
label: 'N3-Name',
address: 'NfuwpaQ1A2xaeVbxWe8FRtaRgaMa8yF3YM'
}
AddressToScriptHash
Converts an address to scripthash.
Input Arguments
Parameter | Description |
---|
address: string | N3 account address. |
Success Response
Parameter | Description |
---|
scriptHash: string | SctiptHash is the script hash of the N3 account. |
/* Example */
neolineN3.AddressToScriptHash({ address: 'NQUN2zkzwpypEi6kvGYexy8cQKN2ycyJjF' })
.then(result => {
const { scriptHash } = result;
console.log('scriptHash' + scriptHash);
})
.catch((error) => {
const {type, description, data} = error;
switch(type) {
case 'NO_PROVIDER':
console.log('No provider available.');
break;
case 'MALFORMED_INPUT':
console.log('Please check your input');
break;
default:
// Not an expected error object. Just write the error to the console.
console.error(error);
break;
}
});
/* Example Response */
{
scriptHash: 'f0a33d62f32528c25e68951286f238ad24e30032'
}
ScriptHashToAddress
Converts a scripthash to address.
Input Arguments
Parameter | Description |
---|
scriptHash: string | SctiptHash is the script hash of the N3 account. |
Success Response
Parameter | Description |
---|
address: string | N3 account address. |
/* Example */
neolineN3.ScriptHashToAddress({ scriptHash: 'f0a33d62f32528c25e68951286f238ad24e30032' })
.then(result => {
const { address } = result;
console.log('address' + address);
})
.catch((error) => {
const {type, description, data} = error;
switch(type) {
case 'NO_PROVIDER':
console.log('No provider available.');
break;
case 'MALFORMED_INPUT':
console.log('Please check your input');
break;
default:
// Not an expected error object. Just write the error to the console.
console.error(error);
break;
}
});
/* Example Response */
{
address: 'NQUN2zkzwpypEi6kvGYexy8cQKN2ycyJjF'
}
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 |
fee?: string | The parsed amount of network fee (in GAS) to include with transaction |
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 */
neolineN3.send({
fromAddress: 'NaUjKgf5vMuFt7Ffgfffcpc41uH3adx1jq',
toAddress: 'NaUjKgf5vMuFt7Ffgfffcpc41uH3adx1jq',
asset: 'GAS',
amount: '1',
fee: '0.0001',
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: '0xd6e4edeb66a75b79bec526d14664017eef9ccee5650c32facb1a4d4fe3640808',
nodeURL: 'https://neo3-testnet.neoline.vip'
};
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
Parameter | Description |
---|
scriptHash: string | Script hash of the smart contract to invoke |
operation: string | Operation on the smart contract to call |
args: Argument[] | Any input arguments for the operation |
fee?: string | The parsed amount of network fee (in GAS) to include with transaction |
extraSystemFee?: string | This fee will be added to system fee |
overrideSystemFee?: string | This fee will override the system fee |
broadcastOverride?: boolean | In the case that the dApp would like to be responsible for broadcasting the signed transaction rather than the wallet provider |
signers: Signers[] | Sender and the effective scope of signature |
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 |
In the case where the "broadcastOverride" input argument is set to True.
Parameter | Description |
---|
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 */
neolineN3.invoke({
scriptHash: '0x1415ab3b409a95555b77bc4ab6a7d9d7be0eddbd',
operation: 'transfer',
args: [
{
type: "Address",
value: "NaUjKgf5vMuFt7Ffgfffcpc41uH3adx1jq",
},
{
type: "Address",
value: "NaUjKgf5vMuFt7Ffgfffcpc41uH3adx1jq",
},
{
type: "Integer",
value: "1",
},
{
type: "Any",
value: null,
}
],
fee: '0.0001',
broadcastOverride: false,
signers: [
{
account: "2cab903ff032ac693f8514581665be534beac39f",
scopes: 16,
allowedContracts: ["0x1415ab3b409a95555b77bc4ab6a7d9d7be0eddbd", "0xef4073a0f2b305a38ec4050e4d3d28bc40ea63f5"],
allowedGroups: []
}
]
})
.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: '0xd6e4edeb66a75b79bec526d14664017eef9ccee5650c32facb1a4d4fe3640808',
nodeURL: 'https://neo3-testnet.neoline.vip'
};
invokeMultiple
Invoke Multiple 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 |
extraSystemFee?: string | This fee will be added to system fee |
overrideSystemFee?: string | This fee will override the system fee |
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. |
signers: Signers[] | Sender and the effective scope of signature |
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 |
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 |
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 |
---|
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 */
neolineN3.invokeMultiple({
invokeArgs: [
{
scriptHash: "ef4073a0f2b305a38ec4050e4d3d28bc40ea63f5",
operation: "transfer",
args: [
{
type: "Address",
value: "NaUjKgf5vMuFt7Ffgfffcpc41uH3adx1jq",
},
{
type: "Address",
value: "NaUjKgf5vMuFt7Ffgfffcpc41uH3adx1jq",
},
{
type: "Integer",
value: "1",
},
{
type: "Any",
value: null
}
]
},
{
scriptHash: "ef4073a0f2b305a38ec4050e4d3d28bc40ea63f5",
operation: "transfer",
args: [
{
type: "Address",
value: "NaUjKgf5vMuFt7Ffgfffcpc41uH3adx1jq",
},
{
type: "Address",
value: "NPsCvedTnzGcwSYuoxjh7Sec5Zem2vgVmX",
},
{
type: "Integer",
value: "1",
},
{
type: "Any",
value: null
}
]
}
],
fee: '0.001',
broadcastOverride: true,
signers: [
{
account: "2cab903ff032ac693f8514581665be534beac39f",
scopes: 1
}
]
})
.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: '0xd6e4edeb66a75b79bec526d14664017eef9ccee5650c32facb1a4d4fe3640808',
nodeURL: 'https://neo3-testnet.neoline.vip'
};
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 the specific string 010001f0
0000
is added to the hexString before signed. For the complete signing process, please go to Testbed.
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 */
neolineN3.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'
}
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. For the complete signing process, please go to Testbed.
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 */
neolineN3.signMessageV2({
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: '023e72b8b5a20c00dac7ac01ecd72354a2d7d64620d6615524bb18b9f5a6ca8ef4',
data: '4fef4abd1ced91577c89eac7909b89ec2aa3d073178c51c3074b7bc5551093b00bf274f35f8166931dc90cbd88346729e86e0bf1c3014fa3587cc167f0cafd4c',
salt: '543e66d70a56506f0a69aff35f25f794',
message: 'Hello world'
}
signMessageWithoutSalt Testbed
Signs a provided messaged with an account selected by user. The specific string 010001f0
0000
is added to the hexString before signed. For the complete signing process, please go to Testbed.
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 |
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 */
neolineN3.signMessageWithoutSalt({
message: 'Hello world'
})
.then(signedMessage => {
const {
publicKey,
message,
data
} = signedMessage;
console.log('Public key used to sign:', publicKey);
console.log('Original message:', message);
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: '"02f9667a14b62a551f25a1b1ec4562e1c963ec6334d1ef5e088f3b5febddf4e648"',
data: '"81bab889bb63fa1225cf4dd98f32e89575908b2510377f58c89bf84f4a71c5a6e8ee7a81f857ad9ee4fb30f1c7a97a2a33a597460186c3a854ec2c7f8b8901b0"',
message: 'Hello world'
}
signMessageWithoutSaltV2 Testbed
Signs a provided messaged with an account selected by user. It is encased in a non-executable transaction before signed. This ensures compatibility with Ledger devices. For the complete signing process, please go to Testbed.
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 |
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 */
neolineN3.signMessageWithoutSaltV2({
message: 'Hello world'
})
.then(signedMessage => {
const {
publicKey,
message,
data
} = signedMessage;
console.log('Public key used to sign:', publicKey);
console.log('Original message:', message);
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: '023e72b8b5a20c00dac7ac01ecd72354a2d7d64620d6615524bb18b9f5a6ca8ef4',
data: '1e810cc032025011df057e99245eece3b7697c27e9b482400130bab576c09f30d9f3bb4414de9ffa623241b231e81d1f089522d1520fb1fdf6c6f34cf9aac7d9',
message: 'Hello world'
}
signTransaction
Sign the provided transaction with the account selected by the user.
Input Arguments
Parameter | Description |
---|
transaction: TransactionLike | The transaction to sign |
magicNumber?: number | Magic number of network found in protocol.json. |
Success Response
Parameter | Description |
---|
transaction: TransactionLike | Signed transaction |
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 */
neolineN3.signTransaction({
transaction: {
version: 0,
nonce: 1262108766,
systemFee: 997775,
networkFee: 122862,
validUntilBlock: 667132,
attributes: [],
signers: [{ account: "8ddd95c4b5aa2b049abae570cf9bd4476e9b7667", scopes: 1 }],
witnesses: [],
script: "0b110c1467769b6e47d49bcf70e5ba9a042baab5c495dd8d0c1467769b6e47d49bcf70e5ba9a042baab5c495dd8d14c01f0c087472616e736665720c14f563ea40bc283d4d0e05c48ea305b3f2a07340ef41627d5b52"
},
magicNumber: 877933390
})
.then(signedTx => {
console.log('Signed Transaction:', signedTx);
})
.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 */
{
version: 0,
nonce: 1262108766,
systemFee: 997775,
networkFee: 122862,
validUntilBlock: 667132,
attributes: [],
signers: [{ account: "8ddd95c4b5aa2b049abae570cf9bd4476e9b7667", scopes: 1 }],
witnesses: [{
invocationScript: "0c408f8bee3201d41706834fb91c8696d59744dfd927bea5a6bddd21d952d231f8836b0386989ecf017a1d0096c0acdb99503d29f65588bc4021b66a80f4b277ad8c",
verificationScript: "0c2102f9667a14b62a551f25a1b1ec4562e1c963ec6334d1ef5e088f3b5febddf4e6484156e7b327"
}],
script: "0b110c1467769b6e47d49bcf70e5ba9a042baab5c495dd8d0c1467769b6e47d49bcf70e5ba9a042baab5c495dd8d14c01f0c087472616e736665720c14f563ea40bc283d4d0e05c48ea305b3f2a07340ef41627d5b52"
}
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 |
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
}
Example
Please instantiate it before calling the common methods and common events of Neo2 and N3. See the example for details.
window.addEventListener('NEOLine.NEO.EVENT.READY', () => {
const neoline = new NEOLine.Init();
});
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 |
chainId:number | ChainId the wallet is currently set to |
defaultNetwork: string | Network the wallet is currently set to |
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 |
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 {
chainId,
networks,
defaultNetwork
} = result;
console.log('chainId: ' + chainId);
// eg. 6
console.log('Networks: ' + networks);
// eg. ["MainNet", "TestNet", "N3TestNet"]
console.log('Default network: ' + defaultNetwork);
// eg. "N3TestNet"
})
.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;
case 'CHAIN_NOT_MATCH':
console.log('The currently opened chain does not match the type of the call chain, please switch the chain.');
break;
default:
// Not an expected error object. Just write the error to the console.
console.error(error);
break;
}
});
/* Example Response */
{
chainId: 6,
networks: ["MainNet", "TestNet", "N3TestNet"],
defaultNetwork: "N3TestNet"
}
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;
case 'CHAIN_NOT_MATCH':
console.log('The currently opened chain does not match the type of the call chain, please switch the chain.');
break;
default:
// Not an expected error object. Just write the error to the console.
console.error(error);
break;
}
});
/* Example Response */
{
address: 'NaUjKgf5vMuFt7Ffgfffcpc41uH3adx1jq',
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: 'NaUjKgf5vMuFt7Ffgfffcpc41uH3adx1jq',
publicKey: '6PYKGV4numxfoswwCedXzhb1oNCC8W4tEdfFPdtWtFa8WidpzYfeJkd2To'
}
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 |
chainId:number | chainId the wallet is currently set 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 |
---|
chainId: number | ChainId is the type of wallet selection network |
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 |
---|
chainId: number | ChainId is the type of wallet selection network |
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 |
CHAIN_NOT_MATCH | The currently opened chain does not match the type of the call chain, please switch the chain |
SCRIPT_ERROR | Script creation error, please check whether the parameters are correct |
FAIL | The request failed |