Neucron
Search
K
Comment on page

Smart Contracts

Neucron Smart Contracts - Writing Custom Locking Script

Overview

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.

Endpoint Details

  • URL: https://dev.neucron.io/tx/asm
  • Method: POST
  • Consumes: application/json
  • Produces: application/json
  • Tags: Smart Contracts
  • Summary: Write Custom Locking Script

Request

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.

Request Example (Python)

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())

Request Example (JavaScript)

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.

Response

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.

Response Codes

  • 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.

Neucron Smart Contracts - Multiple Contract Spending

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.

Endpoint Details

  • URL: https://dev.neucron.io/tx/multiple
  • Method: POST
  • Consumes: application/json
  • Produces: application/json
  • Tags: Smart Contracts
  • Summary: Multiple Contract Spending

Request

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.

Request Body (Example)

{
"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"
}
]
}

Request Example (cURL)

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.

Response

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 the models.BroadcastResponseRaw definition.

Response Codes

  • 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

Neucron Smart Contracts - Sign Custom Output

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.

Endpoint Details

  • URL: https://dev.neucron.io/tx/sign
  • Method: POST
  • Consumes: application/json
  • Produces: application/json
  • Tags: Smart Contracts
  • Summary: Sign Your Custom Output

Request

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.

Request Body (Example)

{
"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"
}
]
}

Request Example (cURL)

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.

Response

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 the models.MultiSignature definition.

Response Codes

  • 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

Neucron Smart Contracts - Unlock Transaction Output

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.

Endpoint Details

  • URL: https://dev.neucron.io/tx/unlock
  • Method: POST
  • Consumes: application/json
  • Produces: application/json
  • Tags: Smart Contracts
  • Summary: Unlock Transaction Output

Request

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.

Request Body (Example)

{
"UnLocking_script": "OP_4 OP_PUSHDATA1",
"output_Index": 0,
"prevTxID": "string"
}

Request Example (cURL)

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.

Response

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 the models.BroadcastResponse definition.

Response Codes

  • 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