({{, (RefLink[BlockchainTransaction, paclet:ref/BlockchainTransaction])[assoc]
represents a blockchain transaction built from the components in the association assoc.}})

OpenersNotesSection(Spacer1)Details

(RefLink[BlockchainTransaction, paclet:ref/BlockchainTransaction]) gives a symbolic representation of a blockchain transaction; it does not submit the transaction, and the transaction is not signed.

(RefLink[BlockchainTransaction, paclet:ref/BlockchainTransaction])[…][prop] gives the value of the property prop for the transaction.

To specify a transaction, the following element must be given in the association:

For Bitcoin transactions, the following additional elements must be given:

The following additional elements can also be given:

Each association in the "Inputs" list must have the following entries:

The following additional entries can also be given:

Possible values for "SignatureHash" include:

For Pay-to-Public-Key-Hash (P2PKH) transactions, each association in the "Outputs" list must have the following entries:

For general Bitcoin transactions, a custom locking script can be given, and each association in the "Outputs" list must have the following entries:

For Ethereum transactions, the following additional elements must be given:

When doing a transfer as an Ethereum transaction, the following elements must be given:

When deploying a contract in an Ethereum transaction, the following element must be given:

When using plain Solidity code, the contract must be a string containing the code, as in  "Contract"->"code".

When using plain Solidity code with multiple contracts, "Contract" must be specified as an association <|"SourceCode"->"code","Main"->"name"|>, where "Main" is the name of the contract to be deployed.

When providing a file containing Solidity code, the contract must be a (RefLink[File, paclet:ref/File]), as in "Contract"->(RefLink[File, paclet:ref/File])[…].

When providing a file containing Solidity code with multiple contracts, "Contract" must be specified as an association <|"Source"->(RefLink[File, paclet:ref/File])[…],"Main"->"name"|>, where "Main" is the name of the contract to be deployed.

When providing multiple files containing Solidity code, "Contract" must be specified as an association <|"Source"->{(Subscript[file, 1]),(Subscript[file, 2]),…},"Main"->"name"|>, where {(Subscript[file, 1]),(Subscript[file, 2]),…} is a list of (RefLink[File, paclet:ref/File]) expressions from which (Subscript[file, 1]) will be compiled and "Main" is the name of the contract to be deployed.

When using compiled Solidity code, "Contract" must be specified as an association of the form <|"ByteCode"->"hexstring","ABI"->"spec"|>, where "ABI" is the Application Binary Interface.

Additionally, when providing an association for "Contract", an extra "Parameters" property can be given to define the initialization parameters of the deploying contract.

When deploying an automatically executed Wolfram contract in an Ethereum transaction, the following elements can be given:

When calling a contract in an Ethereum transaction, the following elements must be given:

The following additional entry can also be given:

The "FunctionCall" element can be an (RefLink[Association, paclet:ref/Association]) or a (RefLink[Typed, paclet:ref/Typed]) expression.

In case "FunctionCall" is a (RefLink[Typed, paclet:ref/Typed]) expression, it must define the function name.

In case "FunctionCall" is an (RefLink[Association, paclet:ref/Association]) expression, the following property must be given:

The following additional properties can also be given to the "FunctionCall" association:

The following additional properties can also be requested from a (RefLink[BlockchainTransaction, paclet:ref/BlockchainTransaction]) object:

OpenersPrimaryExamplesSection(Spacer1)Examples  (12)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

Create a Bitcoin transaction object representing a Pay-to-Public-Key-Hash transaction:

BlockchainTransaction[<|"Inputs"->{<|"TransactionID"->"9bef194418607318673caaf8f45d52fb60e8c8586e6ce8414c377a279ca14399","Index"->0|>},"Outputs"->{<|"Amount"->(QuantityPrefix[0.0002`, "฿" , bitcoins, "Bitcoins"]),"Address"->"munDTMqa9V9Uhi3P21FpkY8UfYzvQqpmoQ"|>,<|"Amount"->(QuantityPrefix[0.16223`, "฿" , bitcoins, "Bitcoins"]),"Address"->"mo9QWLSJ1g1ENrTkhK9SSyw7cYJfJLU8QH"|>},"BlockchainBase"->{"Bitcoin","Testnet"}|>]

Create an Ethereum transaction object to send Ethers:

BlockchainTransaction[<|"TransactionCount"->58,
"GasPrice"->Quantity[1,"GWei"],
"Address"->"3535353535353535353535353535353535353535",
"Amount"->Quantity[0.0025,"Ethers"],
"BlockchainBase"->{"Ethereum","Testnet"}|>]

OpenersExampleSection1(Spacer1)Scope  (10)

OpenersExampleSubsection0(Spacer1)Bitcoin Transactions  (4)

OpenersExampleSubsubsection0(Spacer1)Custom Nonstandard Scripts  (2)

Use a nonstandard script to lock a new output:

BlockchainTransaction[\[LeftAssociation]"BlockchainBase"->{"Bitcoin","Testnet"},
"Inputs"->{
\[LeftAssociation]"TransactionID"->"adf7388f15cc5b115640f1e13e648b9babaee2d32c24185bc46917fc91d03d11","Index"->1\[RightAssociation]
},"Outputs"->{
\[LeftAssociation]"Amount"->0.0001,"Address"->"mkHGstoUaDWzGxag29MEnp8WJPpfA45omK"\[RightAssociation],
\[LeftAssociation]"Amount"->0.0008,"ScriptString"->"OP_3 OP_ADD OP_5 OP_EQUAL"\[RightAssociation]
}\[RightAssociation]]

Use a nonstandard script to unlock a past output:

BlockchainTransaction[\[LeftAssociation]"BlockchainBase"->{"Bitcoin","Testnet"},
"Inputs"->{
\[LeftAssociation]"TransactionID"->"80853fd19713110bf36a778981635c8208669736c81b622a5d2c0efd30ecc4f1","Index"->1,"ScriptString"->"OP_2"\[RightAssociation]
},"Outputs"->{
\[LeftAssociation]"Amount"->0.0007,"Address"->"mgPhDaCzXcm4gmkxfz9sZKvpabmNGdLj52"\[RightAssociation]
}\[RightAssociation]]

OpenersExampleSubsubsection1(Spacer1)Signature Hashes  (1)

Use different values of "SignatureHash" in the transaction inputs:

BlockchainTransaction[\[LeftAssociation]"BlockchainBase"->{"Bitcoin","Testnet"},
"Inputs"->{
\[LeftAssociation]"TransactionID"->"0ad5d33acf0e604c377f134ed7f4f8537d80cbb4fb90397c2bd99dc46a935dc1","Index"->0,"SignatureHash"->"All"\[RightAssociation],
\[LeftAssociation]"TransactionID"->"fdd13f77b31924490f282c0cb8433cd75a20a55f81c9d5a8ad5eb2bf4819c191","Index"->0,"SignatureHash"->"Single"\[RightAssociation],
\[LeftAssociation]"TransactionID"->"ec8169870d16d96d1d498a4f344a7db6e98e79cb1e51e7c553b3e200549e68bb","Index"->0,"SignatureHash"->"None"\[RightAssociation]
},"Outputs"->{
\[LeftAssociation]"Amount"->0.0022,"Address"->"mkHGstoUaDWzGxag29MEnp8WJPpfA45omK"\[RightAssociation],
\[LeftAssociation]"Amount"->0.0001,"Address"->"mgPhDaCzXcm4gmkxfz9sZKvpabmNGdLj52"\[RightAssociation]
}\[RightAssociation]]

OpenersExampleSubsubsection2(Spacer1)Time-Locked Transactions  (1)

Create a transaction that will be locked until block 2000000:

BlockchainTransaction[\[LeftAssociation]"BlockchainBase"->{"Bitcoin","Testnet"},
"LockTime"->2000000,
"Inputs"->{
\[LeftAssociation]"TransactionID"->"20e32abc358790836664a2b5f479a7a72ef9995d3bdd966912593e9ae4e98997","Index"->1\[RightAssociation]
},"Outputs"->{
\[LeftAssociation]"Amount"->0.0008,"Address"->"mkHGstoUaDWzGxag29MEnp8WJPpfA45omK"\[RightAssociation],
\[LeftAssociation]"Amount"->0.0001,"Address"->"mgPhDaCzXcm4gmkxfz9sZKvpabmNGdLj52"\[RightAssociation]
}\[RightAssociation]]

OpenersExampleSubsection1(Spacer1)Ethereum Contracts  (6)

OpenersExampleSubsubsection3(Spacer1)Plain-text Solidity contract deployment   (2)

Build a contract using plain Solidity code in a blockchain transaction:

solidityCode = "pragma solidity ^0.4.23;
contract Test{
	function sum(uint256 a, uint256 b) public pure returns (uint256)
	{
		return a+b;
	}
}
";

BlockchainTransaction[<|"TransactionCount"->58,
"GasPrice"->Quantity[1,"GWei"],
"Contract"->solidityCode,
"BlockchainBase"->{"Ethereum","Testnet"}|>]

Build a contract using plain Solidity code with multiple contract definitions:

solidityCode = "pragma solidity ^0.4.23;

contract Test2{
	function sum(uint256 a, uint256 b) public pure returns (uint256){
		return a+b;
	}
}

contract Test is Test2{
	function main(uint256 a,uint256 b) public pure returns (uint256){
		return sum(a,b);
	}
}";

BlockchainTransaction[<|"TransactionCount"->59,
"GasPrice"->Quantity[1,"GWei"],
"Contract"-><|"SourceCode"-> solidityCode, "Main"-> "Test"|>,
"BlockchainBase"->{"Ethereum","Testnet"}|>]

OpenersExampleSubsubsection4(Spacer1)Filed Solidity contract deployment   (1)

Build a contract using a Solidity file:

Import[File["ExampleData/sample.sol"]]

BlockchainTransaction[<|"BlockchainBase"->{"Ethereum","Testnet"},"TransactionCount"->60,"Contract"->File["ExampleData/sample.sol"],"GasPrice"->Quantity[1,"Gwei"]|>]

Build a contract using a Solidity file with multiple contract definitions:

Import[File["ExampleData/sample2.sol"]]

BlockchainTransaction[<|"BlockchainBase"->{"Ethereum","Testnet"},"TransactionCount"->61,"Contract"-><|"Source"-> File["ExampleData/sample2.sol"],"Main"-> "Test"|>,"GasPrice"->Quantity[1,"Gwei"]|>]

Build a contract using multiple Solidity files:

Import[File["ExampleData/sample3.sol"]]

Import[File["ExampleData/sample4.sol"]]

BlockchainTransaction[<|"BlockchainBase"->{"Ethereum","Testnet"},"TransactionCount"->61,"Contract"-><|"Source"-> {File["ExampleData/sample4.sol"],File["ExampleData/sample3.sol"]},"Main"->"Test4"|>,"GasPrice"->Quantity[1,"Gwei"]|>]

OpenersExampleSubsubsection5(Spacer1)Compiled Solidity contract deployment   (1)

Build a contract using compiled code and its application binary interface:

bytecode="608060405234801561001057600080fd5b506040516104503803806104508339810180604052810190808051820192919060200180518201929190602001805190602001909291905050508260009080519060200190610060929190610087565b508160019080519060200190610077929190610087565b508060028190555050505061012c565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106100c857805160ff19168380011785556100f6565b828001600101855582156100f6579182015b828111156100f55782518255916020019190600101906100da565b5b5090506101039190610107565b5090565b61012991905b8082111561012557600081600090555060010161010d565b5090565b90565b6103158061013b6000396000f300608060405260043610610057576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063047fc9aa1461005c57806306fdde031461008757806354fd4d5014610117575b600080fd5b34801561006857600080fd5b506100716101a7565b6040518082815260200191505060405180910390f35b34801561009357600080fd5b5061009c6101ad565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100dc5780820151818401526020810190506100c1565b50505050905090810190601f1680156101095780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561012357600080fd5b5061012c61024b565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561016c578082015181840152602081019050610151565b50505050905090810190601f1680156101995780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b60025481565b60008054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156102435780601f1061021857610100808354040283529160200191610243565b820191906000526020600020905b81548152906001019060200180831161022657829003601f168201915b505050505081565b60018054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156102e15780601f106102b6576101008083540402835291602001916102e1565b820191906000526020600020905b8154815290600101906020018083116102c457829003601f168201915b5050505050815600a165627a7a72305820116f53a6040b598029b8580eb96cf331f11fc8a7ba722618dfd5dd8df8601f9e0029";

abi="[{\"constant\":true,\"inputs\":[],\"name\":\"supply\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"name\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"version\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"name\":\"_name\",\"type\":\"string\"},{\"name\":\"_version\",\"type\":\"string\"},{\"name\":\"_supply\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"}]";

BlockchainTransaction[<|"BlockchainBase"->{"Ethereum","Testnet"},"TransactionCount"->62,"Contract"-><|"ABI"->abi,"ByteCode"->bytecode,"Parameters"->{"hello","world",10005}|>,"GasPrice"->Quantity[1,"Gwei"]|>]

OpenersExampleSubsubsection6(Spacer1)Wolfram Language contract deployment   (1)

Build a contract using a Wolfram Language expression. This expression will be evaluated by Wolfram servers:

BlockchainTransaction[<|"BlockchainBase"->{"Ethereum","Testnet"},"TransactionCount"->63,"WolframExpression"->Delayed[WeatherData[(Entity["Lima", Entity["City",{"Lima","Lima","Peru"}], "Entity[\"City\", {\"Lima\", \"Lima\", \"Peru\"}]", "city"]),"Temperature"]],"GasPrice"->Quantity[1,"Gwei"]|>]

OpenersExampleSubsubsection7(Spacer1)General contract call   (1)

Create a transaction to do an update value over an state variable in a deployed contract:

contractAddress="D3201000dDa9de4f04F53B50DcfEc9Af3FBA25a7";

BlockchainTransaction[<|"BlockchainBase"->{"Ethereum","Testnet"},"TransactionCount"->65,"Address"->contractAddress,"FunctionCall"-><|"Function"->Typed["setResult",{"string"}->{}],"Inputs"->"ONE"|>,"GasPrice"->Quantity[1,"Gwei"]|>]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[BlockchainTransactionSign, paclet:ref/BlockchainTransactionSign])  ▪  (RefLink[BlockchainTransactionSubmit, paclet:ref/BlockchainTransactionSubmit])  ▪  (RefLink[BlockchainContractValue, paclet:ref/BlockchainContractValue])  ▪  (RefLink[BlockchainTransactionData, paclet:ref/BlockchainTransactionData])  ▪  (RefLink[BlockchainBlockData, paclet:ref/BlockchainBlockData])  ▪  (RefLink[BlockchainData, paclet:ref/BlockchainData])  ▪  (RefLink[BlockchainKeyEncode, paclet:ref/BlockchainKeyEncode])  ▪  (RefLink[CurrencyConvert, paclet:ref/CurrencyConvert])  ▪  (RefLink[Typed, paclet:ref/Typed])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Working with Blockchains, paclet:guide/Blockchain])}})}})