Comment on page
Smart Contracts
The Neucron API allows users to design their own custom locking scripts for smart contracts. This API endpoint,
/tx/asm
, enables users to create and execute custom locking scripts for Bitcoin transactions. Below, you'll find documentation and code examples in both Python and JavaScript to demonstrate how to use this endpoint.- URL:
https://dev.neucron.io/tx/asm
- Method: POST
- Consumes:
application/json
- Produces:
application/json
- Tags: Smart Contracts
- Summary: Write Custom Locking Script
The request to write a custom locking script should include the following parameters:
- X-Neucron-App-ID: A header parameter for specifying the app ID.
- X-Neucron-Key-ID: A header parameter for specifying the key ID.
- X-Neucron-Key-Secret: A header parameter for specifying the key secret.
- X-Neucron-User-ID: A header parameter for specifying the user ID.
- walletID: A query parameter specifying the wallet ID where the transaction should be sent.
- sendRequest: The request body should contain the custom locking script details in the
models.AddLockingstruct
schema. This field is required.
import requests
url = 'https://dev.neucron.io/tx/asm'
headers = {
'accept': 'application/json',
'Authorization': 'YOUR_BEARER_TOKEN',
'Content-Type': 'application/json',
}
data = {
"satoshi": 100,
"script": "OP_DUP OP_HASH160 4a548f3da5526d1e2f8b5c3584ebb9739edfbe3b OP_EQUALVERIFY OP_CHECKSIG"
}
response = requests.post(url, headers=headers, json=data)
print(response.status_code)
print(response.json())
const axios = require('axios');
const url = 'https://dev.neucron.io/tx/asm';
const headers = {
'accept': 'application/json',
'Authorization': 'YOUR_BEARER_TOKEN',
'Content-Type': 'application/json',
};
const data = {
"satoshi": 100,
"script": "OP_DUP OP_HASH160 4a548f3da5526d1e2f8b5c3584ebb9739edfbe3b OP_EQUALVERIFY OP_CHECKSIG"
};
axios.post(url, data, { headers })
.then(response => {
console.log(response.status);
console.log(response.data);
})
.catch(error => {
console.error(error);
});
Replace
'YOUR_BEARER_TOKEN'
with your actual Bearer Token, and customize the satoshi
and script
values as needed for your custom locking script.The API responds with a JSON object containing information about the execution of the custom locking script. Here's the response structure:
{
"data": {
"$ref": "#/definitions/models.BroadcastResponse"
}
}
data
: An object representing the result of executing the custom locking script.
200
: OK - The custom locking script was successfully executed, and the response contains the result.400
: Bad Request - If there's an issue with the request or validation, you'll receive an error response.404
: Not Found - If the specified resource or endpoint is not found, you'll receive an error response.500
: Internal Server Error - If there's a problem with the server, you'll receive an error response.
Please ensure that you provide the correct Bearer Token and customize the
satoshi
and script
values according to your specific locking script requirements when making the request to execute a custom locking script.The Neucron API provides the capability to build new contracts by spending multiple types of contracts. This feature is useful for creating complex smart contracts that involve multiple inputs and outputs. In this documentation, we will cover the
/tx/multiple
endpoint, which allows you to perform multiple contract spending.- URL:
https://dev.neucron.io/tx/multiple
- Method: POST
- Consumes:
application/json
- Produces:
application/json
- Tags: Smart Contracts
- Summary: Multiple Contract Spending
To perform multiple contract spending, you need to send a POST request to the
/tx/multiple
endpoint. The request should include the following parameters:- X-Neucron-App-ID: A header parameter for specifying the app ID.
- X-Neucron-Key-ID: A header parameter for specifying the key ID.
- X-Neucron-Key-Secret: A header parameter for specifying the key secret.
- X-Neucron-User-ID: A header parameter for specifying the user ID.
- walletID: A query parameter specifying the wallet ID where the transaction should be sent.
- sendRequest: The request body should contain the details of the custom transaction builder in the
models.CustomSign
schema. This field is required.
{
"Change_Address": "string",
"Flag": "ALL",
"Input": [
{
"Output_Index": 0,
"Prev_Txid": "string",
"Sequence_Num": 0,
"Unlocking_Script": "OP_4"
}
],
"LockTime": "2006-01-02T15:04:05Z",
"Outputs": [
{
"Amount": 10,
"Asm": "OP_RETURN 7368756268616D"
}
]
}
curl -X 'POST' \
'https://dev.neucron.io/tx/multiple' \
-H 'accept: application/json' \
-H 'Authorization: YOUR_BEARER_TOKEN' \
-H 'Content-Type: application/json' \
-d '{
"Change_Address": "string",
"Flag": "ALL",
"Input": [
{
"Output_Index": 0,
"Prev_Txid": "string",
"Sequence_Num": 0,
"Unlocking_Script": "OP_4"
}
],
"LockTime": "2006-01-02T15:04:05Z",
"Outputs": [
{
"Amount": 10,
"Asm": "OP_RETURN 7368756268616D"
}
]
}'
Replace
'YOUR_BEARER_TOKEN'
with your actual Bearer Token, and customize the request body according to your specific contract spending requirements.The API responds with a JSON object containing information about the multiple contract spending transaction. Here's the response structure:
{
"data": {
"$ref": "#/definitions/models.BroadcastResponseRaw"
}
}
data
: An object representing the result of the multiple contract spending transaction. The structure of this object depends on themodels.BroadcastResponseRaw
definition.
200
: OK - The multiple contract spending transaction was successfully executed, and the response contains the result.400
: Bad Request - If there's an issue with the request or validation, you'll receive an error response.404
: Not Found - If the specified resource or endpoint is not found, you'll receive an error response.500
: Internal Server Error - If there's a problem with the server, you'll receive an error response.
Ensure that you provide the correct Bearer Token and customize the request body according to your specific multiple contract spending transaction needs when making the request to build new contracts by spending multiple types of contracts.
post
https://dev.neucron.io
/tx/multiple
Facilitates creation of complex contracts with multi-contract spending and customizable parameters
The Neucron API provides an endpoint
/tx/sign
that allows users to sign their custom output using a specified sighash flag. This feature is useful for signing transactions when working with smart contracts. The supported flags are ALL
, NONE
, SINGLE
, ALL|ANYONECANPAY
, NONE|ANYONECANPAY
, and SINGLE|ANYONECANPAY
. In this documentation, we will cover how to use this endpoint to sign custom outputs.- URL:
https://dev.neucron.io/tx/sign
- Method: POST
- Consumes:
application/json
- Produces:
application/json
- Tags: Smart Contracts
- Summary: Sign Your Custom Output
To sign a custom output, you need to send a POST request to the
/tx/sign
endpoint. The request should include the following parameters:- X-Neucron-App-ID: A header parameter for specifying the app ID.
- X-Neucron-Key-ID: A header parameter for specifying the key ID.
- X-Neucron-Key-Secret: A header parameter for specifying the key secret.
- X-Neucron-User-ID: A header parameter for specifying the user ID.
- walletID: A query parameter specifying the wallet ID where the transaction should be signed.
- sendRequest: The request body should contain the details of the signing data in the
models.Signature
schema. This field is required.
{
"Change_Address": "string",
"Flag": "ALL",
"Input": [
{
"Output_Index": 0,
"Prev_Txid": "string",
"Sequence_Num": 0,
"privatekey_in_Wif": "string"
}
],
"LockTime": "2006-01-02T15:04:05Z",
"Outputs": [
{
"Amount": 10,
"Asm": "OP_RETURN 7368756268616D"
}
]
}
curl -X 'POST' \
'https://dev.neucron.io/tx/sign' \
-H 'accept: application/json' \
-H 'Authorization: YOUR_BEARER_TOKEN' \
-H 'Content-Type: application/json' \
-d '{
"Change_Address": "string",
"Flag": "ALL",
"Input": [
{
"Output_Index": 0,
"Prev_Txid": "string",
"Sequence_Num": 0,
"privatekey_in_Wif": "string"
}
],
"LockTime": "2006-01-02T15:04:05Z",
"Outputs": [
{
"Amount": 10,
"Asm": "OP_RETURN 7368756268616D"
}
]
}'
Replace
'YOUR_BEARER_TOKEN'
with your actual Bearer Token and customize the request body according to your specific signing requirements.The API responds with a JSON object containing information about the signed transaction. Here's the response structure:
{
"data": {
"$ref": "#/definitions/models.MultiSignature"
}
}
data
: An object representing the result of the signed transaction. The structure of this object depends on themodels.MultiSignature
definition.
200
: OK - The custom output was successfully signed, and the response contains the signed transaction details.400
: Bad Request - If there's an issue with the request or validation, you'll receive an error response.404
: Not Found - If the specified resource or endpoint is not found, you'll receive an error response.500
: Internal Server Error - If there's a problem with the server, you'll receive an error response.
Ensure that you provide the correct Bearer Token and customize the request body according to your specific signing requirements when making the request to sign your custom output.
post
https://dev.neucron.io
/tx/sign
Custom Output Signing
The Neucron API provides an endpoint
/tx/unlock
that allows users to unlock a transaction output by providing the appropriate unlocking script. This feature is useful when working with smart contracts. In this documentation, we will cover how to use this endpoint to unlock a transaction output.- URL:
https://dev.neucron.io/tx/unlock
- Method: POST
- Consumes:
application/json
- Produces:
application/json
- Tags: Smart Contracts
- Summary: Unlock Transaction Output
To unlock a transaction output, you need to send a POST request to the
/tx/unlock
endpoint. The request should include the following parameters:- X-Neucron-App-ID: A header parameter for specifying the app ID.
- X-Neucron-Key-ID: A header parameter for specifying the key ID.
- X-Neucron-Key-Secret: A header parameter for specifying the key secret.
- X-Neucron-User-ID: A header parameter for specifying the user ID.
- sendRequest: The request body should contain the details of the unlocking script in the
models.AddUnLockingstruct
schema. This field is required.
{
"UnLocking_script": "OP_4 OP_PUSHDATA1",
"output_Index": 0,
"prevTxID": "string"
}
curl -X 'POST' \
'https://dev.neucron.io/tx/unlock' \
-H 'accept: application/json' \
-H 'Authorization: YOUR_BEARER_TOKEN' \
-H 'Content-Type: application/json' \
-d '{
"UnLocking_script": "OP_4 OP_PUSHDATA1",
"output_Index": 0,
"prevTxID": "string"
}'
Replace
'YOUR_BEARER_TOKEN'
with your actual Bearer Token and customize the request body according to your specific unlocking script and output details.The API responds with a JSON object containing information about the unlocking status. Here's the response structure:
{
"data": {
"$ref": "#/definitions/models.BroadcastResponse"
}
}
data
: An object representing the result of the unlocking operation. The structure of this object depends on themodels.BroadcastResponse
definition.
200
: OK - The transaction output was successfully unlocked, and the response contains the unlocking status.400
: Bad Request - If there's an issue with the request or validation, you'll receive an error response.404
: Not Found - If the specified resource or endpoint is not found, you'll receive an error response.500
: Internal Server Error - If there's a problem with the server, you'll receive an error response.
Ensure that you provide the correct Bearer Token and customize the request body according to your specific unlocking script and output details when making the request to unlock a transaction output.
post
https://dev.neucron.io
/tx/unlock
Unlocking Transaction Outputs with User-Provided Unlocking Scripts
Last modified 3mo ago