vechain / connex

The mono-repo contains libraries to help build dApps for VeChain.
https://docs.vechain.org/developer-resources/sdks-and-providers/connex
GNU Lesser General Public License v3.0
85 stars 3.6k forks source link

It seems there is no API to deploy smart contract to network yet. #35

Closed duongvansang closed 5 years ago

duongvansang commented 5 years ago

I tried to deploy smart contract by using Thor.Vendor.TXSigningService, but I got ERROR[03-05|15:48:32] executing transaction error="tx not adoptable now".

const signingService = connex.vendor.sign('tx')

signingService
    .signer('0x7567d83b7b8d80addcb281a71d54fc7b3364ffed') // Enforce signer
    .gas(20000000) // Set maximum gas
    .link('https://connex.vecha.in/{txid}') 
    .comment('Deploy new contract')

signingService.request([
    {
        data: '0x608060405234801561001057600080fd5b50610e08806100206000396000f3006080604052600436106100565763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663141961bc811461005b5780634220d6561461009c5780634acb9d4f146100fc575b600080fd5b34801561006757600080fd5b50610073600435610161565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b3480156100a857600080fd5b5060408051602060046024803582810135601f81018590048502860185019096528585526100fa9583359536956044949193909101919081908401838280828437509497506101969650505050505050565b005b34801561010857600080fd5b506101116102d2565b60408051602080825283518183015283519192839290830191858101910280838360005b8381101561014d578181015183820152602001610135565b505050509050019250505060405180910390f35b600080548290811061016f57fe5b60009182526020909120015473ffffffffffffffffffffffffffffffffffffffff16905081565b60003383836101a3610341565b808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200183815260200180602001828103825283818151815260200191508051906020019080838360005b838110156102155781810151838201526020016101fd565b50505050905090810190601f1680156102425780820380516001836020036101000a031916815260200191505b50945050505050604051809103906000f080158015610265573d6000803e3d6000fd5b50600080546001810182559080527f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e56301805473ffffffffffffffffffffffffffffffffffffffff191673ffffffffffffffffffffffffffffffffffffffff92909216919091179055505050565b6060600080548060200260200160405190810160405280929190818152602001828054801561033757602002820191906000526020600020905b815473ffffffffffffffffffffffffffffffffffffffff16815260019091019060200180831161030c575b5050505050905090565b604051610a8b80610352833901905600608060405234801561001057600080fd5b50604051610a8b380380610a8b83398101604090815281516020808401519284015160008054600160a060020a031916600160a060020a038516179055600184905590930180519193909161006b9160029190840190610074565b5050505061010f565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106100b557805160ff19168380011785556100e2565b828001600101855582156100e2579182015b828111156100e25782518255916020019190600101906100c7565b506100ee9291506100f2565b5090565b61010c91905b808211156100ee57600081556001016100f8565b90565b61096d8061011e6000396000f3006080604052600436106100c45763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416630344100681146100c9578063110842cb146100e3578063119f87471461016d5780633410452a146101755780634051ddac1461019c578063481c6a75146101e5578063647c75e21461021657806381d12c581461024b5780638a9cfd551461030d578063937e09b114610377578063c121b1d21461038c578063d7bb99ba146103a1578063d7d1bbdb146103a9575b600080fd5b3480156100d557600080fd5b506100e16004356103c1565b005b3480156100ef57600080fd5b506100f86104a7565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561013257818101518382015260200161011a565b50505050905090810190601f16801561015f5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6100e1610532565b34801561018157600080fd5b5061018a61053c565b60408051918252519081900360200190f35b3480156101a857600080fd5b506101b1610543565b604080519586526020860194909452848401929092526060840152600160a060020a03166080830152519081900360a00190f35b3480156101f157600080fd5b506101fa610560565b60408051600160a060020a039092168252519081900360200190f35b34801561022257600080fd5b50610237600160a060020a036004351661056f565b604080519115158252519081900360200190f35b34801561025757600080fd5b50610263600435610584565b604051808060200186815260200185600160a060020a0316600160a060020a0316815260200184151515158152602001838152602001828103825287818151815260200191508051906020019080838360005b838110156102ce5781810151838201526020016102b6565b50505050905090810190601f1680156102fb5780820380516001836020036101000a031916815260200191505b50965050505050505060405180910390f35b34801561031957600080fd5b506040805160206004803580820135601f81018490048402850184019095528484526100e19436949293602493928401919081908401838280828437509497505084359550505050602090910135600160a060020a0316905061066f565b34801561038357600080fd5b5061018a6107a2565b34801561039857600080fd5b5061018a6107a8565b6100e16107ae565b3480156103b557600080fd5b506100e16004356107e4565b60008054600160a060020a031633146103d957600080fd5b60058054839081106103e757fe5b906000526020600020906005020190508060020160149054906101000a900460ff1615151561041557600080fd5b60045460029004816004015411151561042d57600080fd5b60028101546001820154604051600160a060020a039092169181156108fc0291906000818181858888f1935050505015801561046d573d6000803e3d6000fd5b50600201805474ff000000000000000000000000000000000000000019167401000000000000000000000000000000000000000017905550565b6002805460408051602060018416156101000260001901909316849004601f8101849004840282018401909252818152929183018282801561052a5780601f106104ff5761010080835404028352916020019161052a565b820191906000526020600020905b81548152906001019060200180831161050d57829003601f168201915b505050505081565b61053a6107ae565b565b6005545b90565b6001546005546004546000549293303193600160a060020a031690565b600054600160a060020a031681565b60036020526000908152604090205460ff1681565b600580548290811061059257fe5b60009182526020918290206005919091020180546040805160026001841615610100026000190190931692909204601f81018590048502830185019091528082529193509183919083018282801561062b5780601f106106005761010080835404028352916020019161062b565b820191906000526020600020905b81548152906001019060200180831161060e57829003601f168201915b505050506001830154600284015460049094015492939092600160a060020a03821692507401000000000000000000000000000000000000000090910460ff169085565b61067761086e565b600054600160a060020a0316331461068e57600080fd5b506040805160a0810182528481526020808201859052600160a060020a038416928201929092526000606082018190526080820181905260058054600181018083559282905283518051949593948694929093027f036b6384b5eca791c62761152d0c79bb0604c104a5fb6f4eb0703f3154bb3db0019261071292849201906108a9565b5060208201516001820155604082015160028201805460608501511515740100000000000000000000000000000000000000000274ff000000000000000000000000000000000000000019600160a060020a0390941673ffffffffffffffffffffffffffffffffffffffff1990921691909117929092169190911790556080909101516004909101555050505050565b60015481565b60045481565b60015434116107bc57600080fd5b336000908152600360205260409020805460ff19166001908117909155600480549091019055565b3360009081526003602052604081205460ff16151561080257600080fd5b600580548390811061081057fe5b600091825260208083203384526003600590930201918201905260409091205490915060ff161561084057600080fd5b3360009081526003820160205260409020805460ff1916600190811790915560049091018054909101905550565b60a06040519081016040528060608152602001600081526020016000600160a060020a03168152602001600015158152602001600081525090565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106108ea57805160ff1916838001178555610917565b82800160010185558215610917579182015b828111156109175782518255916020019190600101906108fc565b50610923929150610927565b5090565b61054091905b80821115610923576000815560010161092d5600a165627a7a723058202eb4f25e0f117ce0f463116b6c4d2e423b0a81f271b97618db7a8ee15d9a07600029a165627a7a72305820eb7f2c928ac21f618a6c1303858a7b5869a05db401a3ec90665a911a14e961f60029',
        comment: 'Deploy new contract'
    }
]).then(result=>{
    console.log(result)
})
libotony commented 5 years ago

Gas is greater than the current block gasLimit, so not adoptable now.

Build contract creation clause is one option, but there is another tool for contracts, check this out https://inspector.vecha.in

duongvansang commented 5 years ago

Gas is greater than the current block gasLimit, so not adoptable now.

Build contract creation clause is one option, but there is another tool for contracts, check this out https://inspector.vecha.in

  1. Error message so be better?
  2. https://inspector.vecha.in --> it just contract calling? How do I create new contract from ABI or from bytecode?
libotony commented 5 years ago

Blockchain network will adjust gasLimit, so it is not adoptable now, the tx has the chance to be adopted. We will take this suggestion and consider improving that in the future.

Check the Deploy tab in the header.

duongvansang commented 5 years ago

Oh, responsive issue, when open Sync with small width, tabs is disappear, cannot see any tab

duongvansang commented 5 years ago

actually, when open developer console

duongvansang commented 5 years ago

Blockchain network will adjust gasLimit, so it is not adoptable now, the tx has the chance to be adopted. We will take this suggestion and consider improving that in the future.

Check the Deploy tab in the header.

@libotony There is any way to pass arguments (init data) to create smart contract, I don't see any of it in Transaction Signing Request object on document.

qianbin commented 5 years ago

@duongvansang You can use remix to produce deployment data.

In the right panel, switch to Run and select your contract, then expand Deploy section:

screen shot 2019-03-06 at 1 44 28 pm

Fill in your constructor args, and click Encode values of input fields & copy to clipboard, then you get deployment data.

duongvansang commented 5 years ago

@duongvansang You can use remix to produce deployment data.

In the right panel, switch to Run and select your contract, then expand Deploy section:

screen shot 2019-03-06 at 1 44 28 pm

Fill in your constructor args, and click Encode values of input fields & copy to clipboard, then you get deployment data.

Thank you very much, there is any way to run it from code? it's more flexible and I can develop API, actually the initing values are input by users, it's too difficult for them to use Remix or something like that.

qianbin commented 5 years ago

Here is a piece of demo code in typescript https://gist.github.com/qianbin/3d4734643e8446f76f06cabce0c0c948

qianbin commented 5 years ago

The last line updated

const dataToDeploy = byteCode + coder.encode(1).slice(10 /* remove 0x prefix and 4bytes sig */)
duongvansang commented 5 years ago

The last line updated

const dataToDeploy = byteCode + coder.encode(1).slice(10 /* remove 0x prefix and 4bytes sig */)

It could be work around solution. But I think it's better for developer if you add argument to Transaction Signing Request object, or add a method for encoding data object with both data and argument like encodeABI of web3js

qianbin commented 5 years ago

@duongvansang It's a rare case for an app to provide contract deployment.
Connex does not intent to be an all-in-one utility like web3, but keeps simple, flexible and stable to app developers.

duongvansang commented 5 years ago

@duongvansang It's a rare case for an app to provide contract deployment. Connex does not intent to be an all-in-one utility like web3, but keeps simple, flexible and stable to app developers.

maybe yes, but how about send a transaction to call smart contract method with parameters?

qianbin commented 5 years ago

@duongvansang It's a rare case for an app to provide contract deployment. Connex does not intent to be an all-in-one utility like web3, but keeps simple, flexible and stable to app developers.

maybe yes, but how about send a transaction to call smart contract method with parameters?

https://connex.vecha.in/#/?id=contract-method

libotony commented 5 years ago
const method = connex.thor.account(address).method(ABI)
const clause = method.asClause(args) // this will pack args into one clause

signingService.request([
    clause
]).then(result=>{
    console.log(result)
})
duongvansang commented 5 years ago
address

Ok thank you very much